How To Remove Duplicate Rows in SQL Server

Following code is useful to delete duplicate records in SQL Server.

For Example : Table TABLE_NAME has three columns COL1, COL2 and COL3

Now you can use below script to delete duplicate records from table TABLE_NAME.

DELETE
FROM TABLE_NAME WHERE TABLE_NAME.%%physloc%% NOT IN (SELECT MIN(b.%%physloc%%) FROM TABLE_NAME b GROUP BY b.COL1, b.COL2,b.COL3);

SHARE
    Blogger Comment
    Facebook Comment