Query to Delete Duplicate Records from a Table
Delete Duplicate Records From a Table
Table Structure
Name : Employee
Columns : Emp_ID Identity Column
EMP_Name
DOB
SEX
if you want delete the Duplicate Records based on EMP_Name Column which was existed Previously (i.e. Delete Duplicate Emp_name records except which has Max(Emp_ID))
Delete From Employee Where EMP_ID Not in (
Select Max(EMP_ID) From Employee Where EMP_Name in
(Select EMP_Name From Employee
Group by EMP_Name
Having Count(*) > 1)
group by EMP_Name)
Table Structure
Name : Employee
Columns : Emp_ID Identity Column
EMP_Name
DOB
SEX
if you want delete the Duplicate Records based on EMP_Name Column which was existed Previously (i.e. Delete Duplicate Emp_name records except which has Max(Emp_ID))
Delete From Employee Where EMP_ID Not in (
Select Max(EMP_ID) From Employee Where EMP_Name in
(Select EMP_Name From Employee
Group by EMP_Name
Having Count(*) > 1)
group by EMP_Name)
Share this post
To be informed of the latest articles, subscribe:
Comment on this post
V
B