Mysql删除重复数据保留最小ID

在网上查找删除重复数据保留id最小的数据,方法如下:

 1 DELETE FROM Teacher 
 2        WHERE Name IN(
 3                      SELECT Name 
 4              FROM Teacher 
 5              GROUP BY Name 
 6              HAVING COUNT(Name)>1
 7             )
 8     AND Id NOT IN(
 9              SELECT MIN(Id) 
10              FROM Teacher 
11              GROUP BY Name 
12              HAVING COUNT(Name)>1 
13             )
posted @ 2018-01-16 21:53  順萁洎嘫  阅读(127)  评论(0编辑  收藏  举报