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: Regular Expressions in MySQL queries
Info | 0 Comments
MySQL: GROUP BY range - Count small, medium and large data sets
Tip | 0 Comments
MySQL: Display search results on multiple pages
Tutorial | 0 Comments
MySQL: GROUP BY Day, Month and Year
Question | 3 Answers
MySQL: How many records have been found or are affected by my query?
Info | 0 Comments
MySQL: Check for NULL
Question | 1 Answer
PHP/MySQL: How can I save the output values of $result['COUNT(id)']?
Question | 2 Answers
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.