Remove Duplicate Records

Printer-friendly version

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:

TopLine Strategies delivers the complete integration and development of sales, marketing and customer service technologies that enable corporate clientele to improve revenue streams and strengthen customer interactions. Our project management and consulting is designed to achieve timely delivery, 100 percent user adoption of the technologies we implement and deliver measurable returns on investments for our clients.

Comments (2)

pinaldave replied on

Hello Rod, This is good method. Another method I have it here on following post SQL SERVER - Delete Duplicate Records - Rows Regards, Pinal Dave (http://www.SQLAuthority.com)

mrrodd replied on

Thanks Pinal, it's always good to see how others approach the same issue.

Related Blogs

TheReact Native Open Source roadmap was announced in Q4 2018 after they decided to invest more in the React Native open source community.

October is not just about pumpkins, fall foliage, and cooler temps anymore. October 2018 also means the exciting introduction of Microsoft Dynamics 365 for Customer Engagement.

Back in 2016, Microsoft introduced its intentions to refresh its CRM and ERP strategy with Dynamics 365. At the heart of its services was the Common Data Model (CDM).