Sunday, June 7, 2015

Sql server - delete duplicate rows from a table

Introduction: In this article I will explain how we can delete duplicate rows from a table in Sql server


I have a table “Student” and have the duplicate records.

delete duplicate rows from a table

We can delete the duplicate records of table using row_number().
 

with TempTable as
(
select *, row_number() over (partition by name order by name) as Rank
from Student
)
Delete from TempTable where Rank >1

In the above given example I delete the duplicate records on the basis of duplicate name.

delete duplicate rows from a table

In this article I tried to explain Sql server : delete duplicate rows from a table in Sql server. I hope you enjoyed this article. 

No comments:

Post a Comment