Quantcast
Viewing all articles
Browse latest Browse all 10

Snippet: Query to find dupes in a MySQL table

Wrote this today and thought it might be useful for someone else. It compares the table against itself and tells you if there are any values are identical.

Here’s the SQL:

SELECT *
FROM tablename tn 
WHERE (
   SELECT COUNT(*)  FROM tablename tn2
   WHERE tn2.`fieldname` = tn.`fieldname`
) >= 2

Viewing all articles
Browse latest Browse all 10

Trending Articles