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.
RELATED ARTICLES

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android