方法1:
DELETE FROM titles_test
WHERE id IN(
SELECT a.mid
FROM (
SELECT emp_no,MAX(id) AS mid,COUNT(id) AS num
FROM titles_test
GROUP BY emp_no
) AS a
WHERE a.num>1
)
方法2:
DELETE FROM titles_test
WHERE id NOT IN(
SELECT *
FROM (
SELECT MIN(id) AS mid
FROM titles_test
GROUP BY emp_no
) AS a
)
/*
MySQL的UPDATE或DELETE中子查询不能为同一张表,
可将查询结果再次SELECT。因此下面的写法是错误的,
DELETE FROM titles_test
WHERE id NOT IN(
SELECT MIN(id) AS mid
FROM titles_test
GROUP BY emp_no
)
*/