Count and remove duplicate rows

Let’s consider the Customer table rows:

Customer:

FirstName nvarchar(50)
LastName nvarchar(50)

Some records:

FirstName LastName
AAAAA XXXX
AAAAA XXXX
AAAAA XXXX
AAAAA XXXX
AAAAA XXXX
BBBBB YYYY
BBBBB YYYY
BBBBB YYYY
CCCCC ZZZZ
CCCCC ZZZZ

In order to find duplicate rows from your table (eg. Customer) you can use this snippet:

Following code is useful to delete duplicate records. The table must have identity column, which will be used to identify the duplicate records. For table in example I added CustomerID as Identity Column and Columns which have duplicate data are FirstName and LastName.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.