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
 Finding duplicates using more that one key

Author  Topic 

velvettiger
Posting Yak Master

115 Posts

Posted - 2008-06-16 : 14:13:31
Hi guys,

I was just wondering if any one knows how to find duplicate keys using more than one field. I used the below key to find those people who exists in list1 but don't exists in list2. I realized that the results had some duplicates which was expected but how do I then find all those duplicate people. I know how to do it if there was a primary key present I would have done a
 count (distinct cardnumber) > 1 
and i would have done the select statement like this distinct cardnumber, but how do I do it with more that one key??

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-16 : 14:20:08
SELECT Column1, Column2, COUNT(*) AS DuplicateCount
FROM YourTable
GROUP BY Column1, Column2
HAVING COUNT(*) > 1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -