DELETE FROM t_test
WHERE id IN
(SELECT * FROM
(SELECT MAX(id) did FROM t_test GROUP BY username HAVING COUNT(*) > 1) t);
DELETE FROM t_test
WHERE id NOT IN
(SELECT t.minno FROM
(SELECT MIN(id) AS minno FROM t_test GROUP BY username) t);
执行效率一优于二
原文:https://www.cnblogs.com/landiss/p/14646091.html