SQL Server: How To Find Duplicate Records

Posted October 13, 2009 by Rob Rogers in Database

Last Updated on

When checking the integrity of your data, it may be necessary to check your tables for duplicate records. By grouping these records, you can eliminate the unique records from your result set so that you can view just the records that contain duplicated values, making it easier to remove them.

In our example, we will work with a table named Students and we will look for duplicate values in the Email_Address column.

By using the following SELECT statement, you can isolate the records with duplicate values:

SELECT Email_Address, COUNT(*) FROM Students
Group BY Email_Address HAVING COUNT(*) > 1

You can use the opposite of this to find all rows with unique values in the Email_Address column by using the following SELECT statement:

SELECT Email_Address, COUNT(*) From Students
GROUP BY Email_Address HAVING COUNT(*) = 1


About Rob Rogers

Once a prolific author here on Tech-Recipes, Rob has moved on to greener pastures.
View more articles by Rob Rogers

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply