mysql 表 删除重复信息

来源:互联网 发布:世事洞明皆学问 知乎 编辑:程序博客网 时间:2024/05/22 04:46

hello表










select * from hello where record in (select record from hello group by record having count(record)>1);
select *  from hello where record in (select record from hello group by record having count(record)>1) and id not in (select min(id) from hello group by record having count(record)>1);

create table temp as select * from hello where record in (select record from hello group by record having count(record)>1);
delete from hello where id not in (select record from temp);
drop table temp;

delete from `hello` using `hello`,(select distinct min(`id`) as `id`, `time`, `record` from `hello` group by `time`, `record` having count(1)>1) as `t2` where `hello`.`time` = `t2`.`time` and `hello`.`record` = `t2`.`record` and `hello`.`id` <> `t2`.`id`

参考:http://www.cnblogs.com/consatan/archive/2010/12/17/1909087.html
原创粉丝点击