Thursday, 9 October 2014

Check if column in MySQL table has duplicate values



So you have a column that is not UNIQUE, but you’d still like to check if there is duplicate values in it.

If your column name is my_column in table my_table, the query is:


SELECT my_column, COUNT(*) as count
FROM my_table
GROUP BY my_column
HAVING COUNT(*) > 1

This will return all records that have duplicate my_column content, as well as how many times this content occurs in the database.

0 comments:

Post a Comment