Removing Duplicate Values from Table in SQL Server with the help of Row_Number() function.

Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 221
For removing duplicate values,we have to create a CTE(Common Table Expression) and use Row_Number in-build Sql Server Function.This Row_Number function will generate a unique Table serial no,so that we can easily identify the row number.Here my Table is Employee_Master and CTE is Emp_Details.

With Emp_Details 
Select Row_Number() Over(Partition by Employee_Name
Order By Employee_Name) As RowSerialNumber,* From Employee_Master

Delete From Emp_Deatails Where RowSerialNumber > 1;

Select * From Emp_Deatails Order By Employee_Name;

Here,we have give condition as RowSerialNumber > 1 means,if record is more than 1 for particular name then,it will delete that records.

Comments or Responses

Login to post response