Thursday, June 23, 2011

Deleting Duplicates from MS SQL table

To delete duplicates form a table is very easy. Before you delete any thing from the table make sure to back up the DB or the table before running this command. There is the SQL statement that will do the trick.


DELETE
FROM [table_name]
WHERE [Column_ID] NOT IN
(
SELECT MAX([Column_ID])
FROM [table_name]
GROUP BY [Column name])




Where [Column name] is the column that you think have duplicate value. Give it a shot!!

No comments:

Post a Comment