您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 梅州分类信息网,免费分类信息发布

Mysql删除重复数据保留最小的id

2025/8/1 13:59:13发布4次查看
在网上查找删除重复数据保留id最小的数据,方法如下:
delete from people where peoplename in ( select peoplename from people group by peoplename having count(peoplename) > 1 ) and peopleid not in ( select min(peopleid) from people group by peoplename having count(peoplename) > 1 )
自己使用的时候显示报错:
1 delete from tb where id in (select max(id) from tb group by user having count(user)>1)
[err] 1093 - you can't specify target table ‘xxx’ for update in from clause
暂时不知道是什么原因导致的。
然后想办法分布操作,首先筛选出有重复user的数据,然后用max()选出其中较大的那一行:
select max(id) from tb group by user having count(user)>1
然后再根据得到的max(id)逐条删除多余的数据
1 delete from tb where id=xx
以上就是mysql删除重复数据保留最小的id的详细内容。
梅州分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product