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.
About the Author
You 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
MySQL: Add new Column to a Table
Tutorial | 0 Comments
MySQL: Display search results on multiple pages
Tutorial | 0 Comments
MySQL: Delete Data from Table - Difference between TRUNCATE, DELETE and DROP
Tutorial | 0 Comments
MySQL: GROUP BY range - Count small, medium and large data sets
Tip | 0 Comments
MySQL: How many records have been found or are affected by my query?
Info | 0 Comments
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
MySQL: Group Timestamp Column by Month and Year
Tip | 0 Comments
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.