How to delete duplicate rows?
Posted by Ravi Khanal on Jul 8, 2008
Duplicate rows in a T-SQL can be deleted by using either ROWCOUNT or TOP operator.
If we have a Table name Employee with columns EmpId, EmpLname, EmpFname. If we have some duplicate data for EmpId=1
Then the syntax for deleting duplicate data using ROWCOUNT would be
Set ROWCOUNT 1
DELETE FROM EMPLOYEE WHERE EmpId=1
Set ROWCOUNT 0
By setting the ROWCOUNT 1 we can delete only one duplicate row.
Similarly, we can do it using TOP as,
SELECT TOP(1) FROM EMPLOYEE WHERE EmpId=1
Posted in SQL Server 2005 || No Comments »