Friday, 15 July 2011

Delete duplicate rows using SQL

Here's a quick way to delete duplicate rows - make sure you have backed up, just in case!


First create a temporary table using DISTINCT

CREATE TABLE newtable
SELECT DISTINCT *
FROM oldtable


Then empty the old table

TRUNCATE TABLE oldtable


Then copy the temporary table - this will ensure all the original table settings remain intact

INSERT INTO oldtable
SELECT * FROM newtable


Simplez

No comments:

Post a Comment