Delete Duplicate Rows in Sql Server

Article will cover some best practices on how to delete duplicate rows from sql server table.

We’ll be using a student table. Query for the table creation

Inserted 4 rows into the table, row with roll Number one is repeated twice.

delete duplicate rows in sql server
select * from tbl_Student
following query can be used to check duplicate rows based on rollNumber,

Query result will look like this

delete duplicate rows in sql server
after insertion of rows

and shows that rollNumber with ‘1’ is repeated 2 times.

here I will be explaining two methods for deleting duplicate rows.

Method 1 – by keeping original

In this method all duplicate rows will be deleted except the original copy. Check this query

after deletion, student table will be shown as below

delete duplicate rows in sql server : by keeping original

Method 2 – without keeping original

In this method all repeated rows including original copy will be deleted.

query

resulting table will be like this

delete duplicate rows in sql server

3 thoughts on “Delete Duplicate Rows in Sql Server”

  1. We absolutely love your blog and find the majority of your post’s to be exactly what I’m looking for. can you offer guest writers to write content in your case? I wouldn’t mind creating a post or elaborating on a number of the subjects you write in relation to here. Again, awesome website!

  2. I really do trust each of the concepts you’ve offered on the
    post. They are really convincing and can certainly work.
    Nonetheless, the posts are too quick for starters. Could
    you please extend them a little from subsequent time?
    Thanks for your post.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.