Skip to content
Advertisement

Delete duplicate records in SQL Server?

Consider a column named EmployeeName table Employee. The goal is to delete repeated records, based on the EmployeeName field.

Using one query, I want to delete the records which are repeated.

How can this be done with TSQL in SQL Server?

Advertisement

Answer

You can do this with window functions. It will order the dupes by empId, and delete all but the first one.

Run it as a select to see what would be deleted:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement