我想删除除MySQL数据库表上的所有重复值之外的所有重复值:
我尝试了什么:
DELETE FROM employee WHERE Id NOT IN (
SELECT MIN(Id) FROM (SELECT * FROM employee) AS employeeSub GROUP BY EmpName
)
答案 0 :(得分:1)
嗨,你可以试试这个,
Delete from employee where Id not in (select min(Id) from Employee group by EmpName).
或者您可以使用
WITH a as
(
SELECT EmployeeName,ROW_NUMBER() OVER(PARTITION by EmployeeName ORDER BY EmployeeName)
AS duplicateRecCount
FROM Employee
)
--Now Delete Duplicate Records
DELETE FROM a
WHERE duplicateRecCount > 1