Code Scraps: Finding duplicate records in MySQL

This is a quick code scrap to illustrate how to identify duplicate field values in record sets in MySQL.

The code may also work for other SQL languages, but do check your version of SQL if you have any issues.

SELECT myfield, COUNT(*) count FROM `tablename` GROUP BY myfield HAVING count > 1

In this query, “tablename” is checked to see how many times “myfield” is repeated more than once.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.