You are here

Blog Archive

Remove Duplicate Records

The following is one approach to removing duplicate records from a table assuming the first entry is the one to keep.

DELETE  c1

FROM    dbo.contact c1

            INNER JOIN( SELECT  emailaddress, MIN(contactid) AS contactid

                        FROM    dbo.contact

                        GROUP   BY emailaddress

                        HAVING  COUNT(*) > 1

            ) c2 ON c1.emailaddress = c2.emailaddress

WHERE   c1.contactid > c2.contactid

About the Author: