Finding duplicate entries in MySQL

From time to time I need to check for duplicate entries in my databases. E.g. when I have large numbers of clients signing up for events or similar.

I know there’s ways of deleting multiple entries but sometimes I just need to find out WHO and HOW MANY. The following simple query does just that:

SELECT the_field_name, count(*) AS n FROM the_table GROUP BY the_field_name HAVING n>1;

Hope this proves useful for some of you having the same “problem”.

Should you just wish to remove any duplicate entries then take a look at Justin Cook’s article on the subject.

Comments are closed.