Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to find duplicated rows?

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-06-20 : 15:24:46
Hi there,

Is there any way to find the duplicated rows in a table?
Thanks in advance.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-06-20 : 15:41:08
There are a few different ways:

1. The group by method described here: http://support.microsoft.com/kb/139444

2. You can use the ROW_NUMBER() function - example here: http://nice-tutorials.blogspot.com/2011/09/delete-duplicate-rows-without-primary.html

You can also probably use aggregate functions or distinct clause to do similar things.
Go to Top of Page

comparin.fabio
Starting Member

3 Posts

Posted - 2012-06-20 : 15:43:08
Hi,
try this:

SELECT FIELD1
FROM TABLE1
GROUP BY FIELD1
HAVING COUNT(*) > 1

If FIELD1 has duplicates on table count(*) will be greater than 1
Hope this help.
Bye



CF
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 2012-06-20 : 16:13:40
Guys thank you so much. comparin.fabio's code is exactly what i need!!! The links are also very helpful. Thanks again.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2012-06-20 : 18:42:27
If you'd entered your question into google, or even just looked at the front page you would have got to this point 18 minutes faster!
Go to Top of Page
   

- Advertisement -