Our Blog

Let us find tech solutions together

Jan 31

Find duplicate rows in a database using standard SQL

By kinabalu | Comments

 

Thanks goes to Xgc in #mysql on freenode for showing me this little one-liner. We needed to add a unique key to one of our tables, and a duplicate was in our midst. Enter this handy one-liner:

1
SELECT field1, count(*) FROM tbl1 GROUP BY field1 HAVING count(*) > 1;

problem solved, a nice simple list of the duplicated rows in front of you.