Home > Database > Mysql Tutorial > mysql删除表中某一字段重复的记录

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 18:00:30
Original
1269 people have browsed it

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

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template