In my last article on delete duplicate rows i have used primary key to remove duplicate rows from the datatable

DELETE DUPLICATE ROWS FROM A TABLE IN SQL SERVER 2005 — Last article on duplicate rows

One can use the below query if the primary key is not there in the table.

SET ROWCOUNT 1

SELECT * FROM EMPLOYEE
WHILE @@ROWCOUNT > 0
DELETE FROM EMPLOYEE WHERE EMPNAME IN (SELECT DISTINCT EMPNAME FROM EMPLOYEE GROUP BY EMPNAME HAVING COUNT(*) > 1)

SET ROWCOUNT 0

Pawan Kumar

Pawankkmr@hotmail.com