11 Vote

MySQL: Find Duplicate Entries in Database

Tip by Stefan Trost | 2012-05-28 at 21:19

With this MySQL query, we get all records that have the same value more than once in a given column:

SELECT * FROM tab GROUP BY col HAVING COUNT(*) > 1;

Thus we find all records from the table "tab", which have duplicates in the column "col".

We can also use the reverse of this query to find all records that exist only once in the table:

SELECT * FROM tab GROUP BY col HAVING COUNT(*) = 1;

Of course, you have to replace "col" in the query with the name of the column in which you would like to search for duplicates. Similarly, you have to substitute "tab" with the name of your table.

ReplyPositiveNegative

About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.