How to Delete Duplicate Rows in Sql Server - CodAffection
[the_ad_placement id="before-content"]

How to Delete Duplicate Rows in Sql Server

How to remove duplicate rows in sql server


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

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

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

sql server table with duplicate rows - Dotnetmob

select * from tbl_Studentfollowing query can be used to check duplicate rows based on rollNumber,

find duplicate rows in sql server

Query result : Output 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 but keep original

Method 2 – without keeping original

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


resulting table will be like this

Video Tutorial Available For This Topic – Watch Now!

Scroll to Top
Share via
Copy link
Powered by Social Snap