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 |
|
spib
Starting Member
9 Posts |
Posted - 2002-08-31 : 19:43:18
|
| Hi,I've seen a few articles in here about deleting duplicates etc but what I need to do is list all my duplicate records. They will only be assessed on whether they are duplicates on two columns out of ten (the other 8 may well contain different data).Any help much appreciatedJames |
|
|
r937
Posting Yak Master
112 Posts |
Posted - 2002-08-31 : 21:25:43
|
| i'm not sure i understand the problemdoes this give you what you want?select col1, col2, ... , col10 from yourtable where col1 || col2 in ( select col1 || col2 from yourtable group by col1, col2 having count(*) > 1 )rudyhttp://rudy.ca/ |
 |
|
|
spib
Starting Member
9 Posts |
Posted - 2002-09-01 : 04:59:17
|
| Sorry if I wasn't clear. What I need to show is all the duplicate records so we get this sort of thingCOL1 COL2 COL3------------------------foo bar bunfoo bar sunfoo mar funfoo mar runmoo cow bunmoo cow sunThe first two fields are used to decide if the record is a duplicate.BTW I ran your code but SQLServer choked on the '||' sign. |
 |
|
|
r937
Posting Yak Master
112 Posts |
Posted - 2002-09-01 : 05:02:09
|
replace the || with a plus sign (concatenation) -- i originally had a plus sign but the forum software kept hiding it |
 |
|
|
VyasKN
SQL Server MVP & SQLTeam MVY
313 Posts |
Posted - 2002-09-01 : 05:08:50
|
| Here is an example:CREATE TABLE Dups( i int, j char, k datetime)GOCREATE CLUSTERED INDEX myIdx ON Dups(i, j)GOINSERT Dups SELECT 1, 'A', GETDATE()INSERT Dups SELECT 1, 'A', GETDATE()INSERT Dups SELECT 2, 'B', GETDATE()INSERT Dups SELECT 3, 'C', GETDATE()INSERT Dups SELECT 3, 'C', GETDATE()INSERT Dups SELECT 4, 'D', GETDATE()INSERT Dups SELECT 5, 'E', GETDATE()INSERT Dups SELECT 5, 'E', GETDATE()GOSELECT d1.i, d1.j, d1.kFROM Dups d1 JOIN(SELECT i, jFROM DupsGROUP BY i, jHAVING COUNT(*) > 1) AS d2ON d1.i = d2.i AND d1.j = d2.j--HTH,Vyashttp://vyaskn.tripod.com |
 |
|
|
|
|
|
|
|