MYSQL: delete duplicates and leave with minimal id
SQL query to delete all duplicates.
DELETE i FROM stats i
JOIN (SELECT *, min(id) as minid
FROM stats GROUP BY custom_id, code
HAVING COUNT(*)>1) AS dups
ON dups.custom_id=i.custom_id AND dups.code=i.code
WHERE i.id <> dups.minid
Comments
comments powered by Disqus