How to Find Duplicate Values in MySQL
Identify duplicate rows safely using SQL before performing cleanup or deletion.
Before you start
Find duplicates by single column
SELECT column_name, COUNT(*) as cnt
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
Groups rows by the target column and returns only values that appear more than once.
Find duplicates by multiple columns
SELECT col1, col2, COUNT(*) as cnt
FROM table_name
GROUP BY col1, col2
HAVING COUNT(*) > 1;
Useful when duplicates are defined by a combination of values, such as email + date or user_id + product_id.
View full duplicate rows
SELECT *
FROM table_name
WHERE column_name IN (
SELECT column_name
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1
);
This lets you inspect the actual duplicate rows before taking any action.
Common mistakes
Choosing a column that is not meant to be unique leads to misleading results.
NULL values may behave differently and should be checked separately if needed.
Always review duplicates before deletion or updates.