Forum Moderators: coopster

Message Too Old, No Replies

Quick way to find duplicates in DB

Anybody know a quick SQL query

         

surfgatinho

5:46 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I need to make a field in a DB unique, however I can't because there are duplicate entries.

Does anybody know an SQL query I can run that will find these duplicates so I can remove them.

Thanks in advance,
Chris

kamakaze

6:19 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



SELECT field,
COUNT(field) AS NumOccurrences
FROM table
GROUP BY field
HAVING ( COUNT(field) > 1 )

That should do the trick.

surfgatinho

8:37 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks kamakaze, you're a star!
Had forgotten all about HAVING clauses

badone

11:01 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



Thanks for this topic guys. I've been looking for this.

Cheers,
BAD