How to Find Duplicates in a Table using SQL

Problem

Write an SQL statement to find rows with duplicate column values in a database table

Solution

You need to group by the column containing the duplicate values then select only the groups with count greater than 1

Code

Here is the code in SQL

Select field, count(field)
from table 
group by field 
having count(field) > 1

Leave a Reply