mysql刪除表中某一字段反復的記載。本站提示廣大學習愛好者:(mysql刪除表中某一字段反復的記載)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql刪除表中某一字段反復的記載正文
好比,表:event(id int(10) auto_increment primary key,
sid int(10)not null,
detail text)
我想刪除表event中sid反復的記載,請問有無如許SQL語句?或是經由過程其它辦法?
delete from event as e
where id != (select min(id) from event where sid=e.sid);
or
delete from event
where sid not in (select mid from (select sid ,min(id) as mid from event group by sid))
應當是有效的代碼
alter ignore table event add unique index idu_sid (sid);
alter table event drop index idu_sid;