There are multiple options to perform this operation.
Using row count to restrict delete only 1 record
set rowcount 1
DELETE FROM EMPLOYEE WHERE EMPID IN (
SELECT EMPID
FROM EMPLOYEE
GROUP BY EMPID,EMPNAME, SALARY
HAVING COUNT(*)>1
)
set rowcount 0
-======================-=======================
Use auto increment primary key "add" if not available in the table, as in given example.
alter table employee
add empidpk int identity (1,1)
Now, perform query on min of auto pk id, group by duplicate check columns - this will give you latest duplicate records
select * from employee where
empidpk not in ( select min(empidpk) from employee
group by EMPID,EMPNAME, SALARY )
Now, delete.
Delete from employee where
empidpk not in ( select min(empidpk) from employee
group by EMPID,EMPNAME, SALARY )
--------------------------------------------------------------------------------------------------------------
From article ---
http://www.c-sharpcorner.com/article/most-asked-sql-queries-in-interview-questions/
-------------------------------------------------------------------------------------------------------------