MySQL 去重

  • 方式一
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);

执行效率一优于二

posted on 2021-04-11 23:13  landiss  阅读(39)  评论(0编辑  收藏  举报