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 去重

上一篇:【游戏开发备注之三】GameCenter登陆出现“无法识别此游戏”问题的两种解决方法


下一篇:MySQL中 插入数据(insert)的语法 怎么用?