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 |
runnerpaul
Starting Member
24 Posts |
Posted - 2008-08-05 : 11:16:17
|
If I have a table with fields A, B, C and D. Can anybody tell me how to do a query that will produce any records that have buplicate fleids A, C and D or duplicate fields B, C and B?CheersPaul |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-05 : 14:04:49
|
[code]SELECT t.*FROM YourTable tLEFT JOIN (SELECT A,C,D FROM YourTable GROUP BY A,C,D HAVING COUNT(*) >1 )t1ON t1.A = t.AAND t1.C=t.CAND t1.D=t.DLEFT JOIN (SELECT B,C,D FROM YourTable GROUP BY B,C,D HAVING COUNT(*) >1 )t2ON t2.B = t.BAND t2.C=t.CAND t2.D=t.DWHERE t1.A IS NOT NULLOR t2.B IS NOT NULL[/code] |
|
|
runnerpaul
Starting Member
24 Posts |
Posted - 2008-08-06 : 04:56:08
|
Cheers visakh16. That was a big help. |
|
|
runnerpaul
Starting Member
24 Posts |
Posted - 2008-08-06 : 05:52:20
|
Would you then know how I could delete these duplicate records?CheersPaul |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-07 : 13:54:55
|
Just modify the above query with delete |
|
|
|
|
|