How to delete duplicate records using MSSQL

To delete duplicate records using MSSQL you can use the following snippet.
The table must have identity column, which will be used to identify the duplicate records.

DELETE
FROM TableName
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM TableName
GROUP BY ColumnWithDuplicatesName)

Please Share us:
Please rate this snippet

6 thoughts on “How to delete duplicate records using MSSQL

Leave a Reply