MySQL 去重

2021/4/12 2:25:24

本文主要是介绍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);

执行效率一优于二



这篇关于MySQL 去重的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程