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.

usernameemail
Vishalvishal@example.com
Ram ram@example.com
Alexalex@example.com
Ramram@example.com
Alexalex@example.com
Vishalvishal@example.com
Bobbob@example.com
SELECT  username, email, COUNT(*) 
FROM table_name 
GROUP BY username, email
HAVING count(*) > 1;

Query result.

usernameemailcount
Vishalvishal@example.com2
Ramram@example.com2
Alexalex@example.com2

How to delete duplicates from a table

Leave a Reply

Your email address will not be published. Required fields are marked *