mysql对表中数据根据某⼀字段去重要删除重复的记录,就要先查出重复的记录,这个很容易做到
select*from表名group by根据哪⼀个字段(简称字段)having count(字段) >1
注意:这是查出所有重复记录的第⼀条记录,需要保留,因此需要添加查询条件,查出所有的重复记录select id,expect from cqssc where expect in (select expect from cqssc group by expect having count(expect)>1)
and id not in(select min(id) from cqssc group by expect having count(expect)>1)mysql删除重复的数据保留一条
然后
delete from cqssc where id in (select id from (select id from cqssc where expect in
(select expect from cqssc group by expect having count(expect)>1) and id not in
(select min(id) from cqssc group by expect having count(expect)>1)) as tmpresult)
删除成功,最后再查询⼀下看是否还有重复记录

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。