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 the doplicated entities

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-05-18 : 16:25:17
Hi
I have the following table where I want to write two queries to find the duplicated records or the ones who have the duplicate keys (the same combination of set elements O-D-C-M) but different value for V0.


1st query: find the duplicated records with the same value for ODCMV0
2nd query: find the duplicated keys of ODCM with different value for V0.

Thank you

O D C M V0
04000US01 010 2 02 4
04000US01 010 3 02 4
04000US01 010 5 02 4
04000US01 010 2 03 730
04000US01 010 3 03 644
04000US01 010 4 03 402
04000US01 010 5 03 242
04000US01 010 6 03 86
04000US01 010 13 03 15
04000US01 010 15 03 15
04000US01 010 19 03 61
04000US01 010 2 04 712
04000US01 010 3 04 712

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-18 : 16:29:56
SELECT O,D,C,M,V0 FROM myTable GROUP BY O,D,C,M,V0 HAVING COUNT(*)>1

SELECT O,D,C,M FROM myTable GROUP BY O,D,C,M HAVING COUNT(DISTINCT V0)>1
Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-05-19 : 09:15:55
Thank you so much. It worked:))))
Go to Top of Page
   

- Advertisement -