Employees table :
| ID | FirstName | LastName | Gender | Salary |
+------+-----------+----------+--------+--------+
| 1 | Mark | Hastings | Male | 60000 |
| 1 | Mark | Hastings | Male | 60000 |
| 2 | Mary | Lambeth | Female | 30000 |
| 2 | Mary | Lambeth | Female | 30000 |
| 3 | Ben | Hoskins | Male | 70000 |
| 3 | Ben | Hoskins | Male | 70000 |
| 3 | Ben | Hoskins | Male | 70000 |
+------+-----------+----------+--------+--------+
CTE (Common Table Expression) :
WITH EmployeesCTE AS
(
SELECT *, ROW_NUMBER()OVER(PARTITION BY ID ORDER BY ID) AS RowNumber
FROM Employees
)
DELETE FROM EmployeesCTE WHERE RowNumber > 1
Execution result :
| ID | FirstName | LastName | Gender | Salary |
+------+-----------+----------+--------+--------+
| 1 | Mark | Hastings | Male | 60000 |
| 2 | Mary | Lambeth | Female | 30000 |
| 3 | Ben | Hoskins | Male | 70000 |
+------+-----------+----------+--------+--------+