Thursday, April 4, 2013

How to delete duplicate records in sql without using temporary table

DELETE FROM table 
WHERE name IN (SELECT name FROM table GROUP BY name HAVING COUNT(*) > 1)
AND NOT id IN (SELECT min(id) FROM table GROUP BY name)

No comments: