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.
| 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 ODCMV02nd query: find the duplicated keys of ODCM with different value for V0.Thank youO D C M V004000US01 010 2 02 404000US01 010 3 02 404000US01 010 5 02 404000US01 010 2 03 73004000US01 010 3 03 64404000US01 010 4 03 40204000US01 010 5 03 24204000US01 010 6 03 8604000US01 010 13 03 1504000US01 010 15 03 1504000US01 010 19 03 6104000US01 010 2 04 71204000US01 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(*)>1SELECT O,D,C,M FROM myTable GROUP BY O,D,C,M HAVING COUNT(DISTINCT V0)>1 |
 |
|
|
goligol
Posting Yak Master
128 Posts |
Posted - 2011-05-19 : 09:15:55
|
| Thank you so much. It worked:)))) |
 |
|
|
|
|
|
|
|