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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 All accept DISTINCT records, the duplicates?

Author  Topic 

bluefish
Starting Member

1 Post

Posted - 2003-01-11 : 06:13:31
Hello!

I want to select all rows accept the ones that are DISTINCT. Im looking for duplicate strings that exist more than once in the same column.

Like this:
ID fldString
1 string1
2 string2
3 string3
4 string4 <---
5 string4 <---
6 string5
7 string6

So, its easy to select the DISTINCT values, but how about all accept the DISTINCT values.

In this case string4 should be returned, and also if there are any other duplicates.

Thanks for any help!

/Marcus



SamC
White Water Yakist

3467 Posts

Posted - 2003-01-11 : 12:28:00
This problem appears easy at first:

SELECT fldString
FROM MyTable
GROUP BY fldString
HAVING Count(*) > 1

The *next problem* is how to delete JUST ONE of the duplicates.

There is a short article on how to do exactly this on sqlteam's home page, search for "duplicate" in the Article Search.

The article is titled "Deleting Duplicate Records".

HTH

Sam

Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2003-01-13 : 22:26:40
Check out this link:
http://sqlteam.com/Forums/topic.asp?TOPIC_ID=21164
Emanaton made this procedure. It has several params, as you can see for yourself, which are very handy (and make this proc one which you like to keep for later use), one of which lets you specify whether to delete the dups or not.
I'm running SQL 7, and when I ran this proc, I got several syntax errors, but the sp did run, and do its work. Since it worked, I never bothered to debug it. Maybe it's using some stuff that doesn't work in SQL 7 (like table vars), I should really check. I'm just telling you this so you shouldn't think the sp isn't working.

Sarah Berger MCSD
Go to Top of Page
   

- Advertisement -