How To Remove Duplicate Rows in SQL Server

September 05, 2012 , 0 Comments

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);

Prakash Hari Sharma
I'm a software developer and Java enthusiast. I like clean and modular code, enjoy Agile projects and have a passion for trying out new things. I try to learn and teach every day, and occasionally I'm even able to blog about it. :)