Or in Oracle
SELECT A.* FROM TABLE1 A,TABLE1 B
WHERE A.COL1=B.COL1 AND A.ROWID<>B.ROWID
Steve
Main Topics
Browse All TopicsHi all,
How would you write a query that would search a particular column in a table to show duplicates?
Thanks for any input.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Silvers5
When using the following code I get this error:-
strQuery = "Select Link, Count(Link) as cnt from Rlinks Order by cnt desc group by Link having cnt > 1"
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'group'.
Thats worked. I am using this to display the duplicates:-
While Not objRS.EOF
response.write objrs("Link")
objRS.MoveNext
Wend
However it only shows 1 URL that I have duplicated (Which I expected). How would i display the Record ID of both the duplicated records So I could write a peice of code to delete the unrequired one?
It was the string that was suggested by acperkins
strQuery = "Select Link, Count(Link) As cnt From Rlinks Group By Link Having cnt > 1 Order By cnt Desc"
Error:-
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'cnt'.
/test/showlinks.asp, line 14
>>However it only shows 1 URL that I have duplicated (Which I expected). How would i display the Record ID of both the duplicated records So I could write a peice of code to delete the unrequired one?<<
In order to get all the duplicated records, you can use a sub-query as follows:
strQuery = "Select * From Rlinks Where Link In (Select Link From Rlinks Group By Link Having Count(Link) > 1)"
Anthony
If the order is important than it gets a little more complicated, but very doable (I will break it down to make it more readable):
Select Rlinks.*
From Rlinks
Inner Join (Select Link,
Count(Link) As Cnt
From Rlinks
Group By
Link
Having Count(Links) > 1) A On Rlinks.Link = A.Link
Order By
A.Cnt Desc
You can of course limit the fields to just the one you need as follows (for example):
Select Rlinks.ID,
Rlinks.Link
From Rlinks
Inner Join (Select Link,
Count(Link) As Cnt
From Rlinks
Group By
Link
Having Count(Links) > 1) A On Rlinks.Link = A.Link
Order By
A.Cnt Desc
Run these queries in the Query Analyzer first and you will see it will give you the right results.
Anthony
Anthony your post of 02:14PM PST works fine. (I have not tried the other posts because order does not matter ~ However when I have time I will play around with it.)
I did try to get Rlinks.ID. But came back with "Invalid column name 'ID'". That would work if I was using access because that field is manditory, however I am using SQL server Is there an internal uniquie field that I could use?
Pete
Unfortunately, there in no internal unique field that i know of in SQL Server which you can use as key. You will need to create a surrogate key.
However, it will be great to see the list of columns that you have at present. One MIGHT turn out to be unique.
And if there is no other information attached to the two separate rows of same url, how does it matter which one you delete?
>>That would work if I was using access because that field is manditory, however I am using SQL server Is there an internal uniquie field that I could use?<<
In this aspect Access is no different from SQL Server. If there is a column called ID in SQL Server (or Access) than you should be able to display with:
strQuery = "Select * From Rlinks Where Link In (Select Link From Rlinks Group By Link Having Count(Link) > 1)"
Or explicitly with:
strQuery = "Select ID, Link From Rlinks Where Link In (Select Link From Rlinks Group By Link Having Count(Link) > 1)"
Anthony
Business Accounts
Answer for Membership
by: NitinSontakkePosted on 2002-06-22 at 01:51:30ID: 7100272
If you have an access to MSDN following article could be of help:
INF: How to Remove Duplicate Rows From a Table
Q139444
I have pasted below the portion of sample from above article:
create table t1(col1 int, col2 int, col3 char(50))
insert into t1 values (1, 1, 'data value one')
insert into t1 values (1, 1, 'data value one')
insert into t1 values (1, 2, 'data value two')
To identify which rows have duplicate primary key values:
SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1