Method - 1:
set rowcount 1
DELETE FROM EMPLOYEE WHERE EMPID IN (
SELECT EMPID FROM EMPLOYEE
GROUP BY EMPID
HAVING COUNT(*)>1
)
set rowcount 0
Method - 2:
WITH cte AS (SELECT *,ROW_NUMBER() OVER(PARTITION BY EMPID ORDER BY EMPID)'RowRank'
FROM EMPLOYEE)
DELETE FROM cte
WHERE RowRank > 1
set rowcount 1
DELETE FROM EMPLOYEE WHERE EMPID IN (
SELECT EMPID FROM EMPLOYEE
GROUP BY EMPID
HAVING COUNT(*)>1
)
set rowcount 0
Method - 2:
WITH cte AS (SELECT *,ROW_NUMBER() OVER(PARTITION BY EMPID ORDER BY EMPID)'RowRank'
FROM EMPLOYEE)
DELETE FROM cte
WHERE RowRank > 1
0 Comments