HomeDatabaseSQL Server: How To Find Duplicate Records

SQL Server: How To Find Duplicate Records

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

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


Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

error: Content is protected !!