首页 > 数据库技术 > 详细

MySQL 去重

时间:2021-04-12 09:06:44      阅读:28      评论:0      收藏:0      [点我收藏+]
  • 方式一
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 去重

原文:https://www.cnblogs.com/landiss/p/14646091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!