Delete all duplicates rows except one in SQL Server

In this post, I demonstrate two different SQL script to delete all duplicate rows except the one in SQL Server.

Before a few days ago, I was working on one production report and found duplicates records in some of our tables. I have worked around this and created different solution to remove all duplicate rows.
Let’s first create sample table and data:

First solution is using WITH CTE:

Second solution is using SELF JOIN:

Check your table after remove this duplicate:

As per your requirement you can use any one of this solution and before execute please check your query plan and choose best solution to delete duplicate rows in SQL Server.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of