mysql删除表中某一字段重复的记录

数据库评论289字数 137阅读模式

一般大家也许会碰到这个问题,大家可以参考下,讲的比较详细

比如,表:event(id int(10) auto_increment primary key,
sid int(10)not null,
detail text)很文博客-https://www.zhenjiekeji.com/59449.html

我想删除表event中sid重复的记录,请问有没有这样SQL语句?或是通过其它方法?很文博客-https://www.zhenjiekeji.com/59449.html

  1. delete from event as e
  2. where id != (select min(id) from event where sid=e.sid);

or很文博客-https://www.zhenjiekeji.com/59449.html

  1. delete from event
  2. where sid not in (select mid from (select sid ,min(id) as mid from event group by sid))

应该是有用的代码很文博客-https://www.zhenjiekeji.com/59449.html

  1. alter ignore table event add unique index idu_sid (sid);
  2. alter table event drop index idu_sid;

 很文博客-https://www.zhenjiekeji.com/59449.html 很文博客-https://www.zhenjiekeji.com/59449.html

weinxin
我的微信
微信号已复制
扫一扫更精彩
大家的支持是我更新的动力!!!
匿名

发表评论

匿名网友