码迷,mamicode.com
首页 > 数据库 > 详细

Mysql 删除重复记录,只保留最小的一条

时间:2016-04-01 17:45:25      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

delete from `jb_postcontent` where id not in(select min(id) from (select * from `jb_postcontent`) as t group by t.id);

网上搜索的大部分都是如下这样

delete from people   
where peopleId in (select peopleId from people group by peopleId   having count(peopleId) > 1)   
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)   

结果你会发现,mysql报错,因为不能更新用于子查询里面的表。

Mysql 删除重复记录,只保留最小的一条

标签:

原文地址:http://www.cnblogs.com/aleafo/p/5345603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!