比如,表: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;