1/28/2008

Find duplicate rows in SQL

Filed under: Developing — Guus @ 11:54 am

Sometimes you need to know for sure that a column value is only used once in a table. Example: you don’t want to have more then 1 record with a social security number. Or maybe you are searching for a duplicate GUID (which BTW should be globally unique). Browsing by hand is not an option: the table is too large. And also the values to compare are difficult to read.

There is only 1 one way to tell for sure, use SQL:

SELECT * from <tablename> where __guid in (
    SELECT __guid
    FROM <tablename>
    GROUP BY __guid
    HAVING count(__guid) >= 2
)

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .