Thursday, November 11, 2010

Deleting Duplicate Records

Similar to this post http://damianfiles.blogspot.com/2009/04/finding-duplicate-records.html, the below SQL will delete any records that have 'dupField' in common. It will keep the record that has the lowest 'uniqueField' value.

delete T1
from MyTable T1, MyTable T2
where T1.dupField = T2.dupField
and T1.uniqueField > T2.uniqueField

Found here http://www.cryer.co.uk/brian/sql/sql_delete_duplicates.htm.

No comments:

Post a Comment