Finding Duplicates in MySQL

Posted November 25th @ 11:31 am  |  Filed in: mysql    

I get quite a few Excel files from clients that need to get cleaned up and inserted in to MySQL. Sometimes the import goes smoothly, sometimes it doesn’t. This last time, I had 3,741 rows in an Excel file, but somehow wound up with 3,751 rows in the database - what went wrong? Don’t know, and don’t have time to figure it out - so I just used this query to isolate all the duplicates.

My database table consists of nothing more than an id, a part number (number), a description, and a price. Here’s the query that located all duplicate part numbers - from there I was able to easily delete them:

SELECT number,
 COUNT(number) AS NumOccurrences
FROM part_prices_new
GROUP BY number
HAVING ( COUNT(number) > 1 )

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login

Options:

Size

Colors