Identify duplicates criteria
The first step is to define your criteria for a duplicate row. Do you need a combination of two columns to be unique together, or are you simply searching for duplicates in a single column? In this example, we are searching for duplicates across two columns in our Users table: username and email.
| username | |
| Vishal | vishal@example.com |
| Ram | ram@example.com |
| Alex | alex@example.com |
| Ram | ram@example.com |
| Alex | alex@example.com |
| Vishal | vishal@example.com |
| Bob | bob@example.com |
SELECT username, email, COUNT(*)
FROM table_name
GROUP BY username, email
HAVING count(*) > 1;Query result.
| username | count | |
| Vishal | vishal@example.com | 2 |
| Ram | ram@example.com | 2 |
| Alex | alex@example.com | 2 |