MYSQL中删除重复记录的方法
2009-06-24 16:15
357 查看
共有三种方法,前两种是利用临时表,下面分别说明:
1、
create temporary table tmp_news select * from news group by nid having count(1) >= 1;
truncate table news;
insert into news select * from tmp_news;
drop table tmp_news;
2、
新建一个临时表
create table tmp_news as select * from news group by nid;
删除原来的表
truncate table youtable;
重命名表
alter table tmp_news rename news;
3、
查找重复的,并且除掉最小的那个。
delete news as a from news as a,
(
select *,min(id) from news group by nid having count(1) > 1
) as b
where a.nid = b.nid and a.id > b.id;
1、
create temporary table tmp_news select * from news group by nid having count(1) >= 1;
truncate table news;
insert into news select * from tmp_news;
drop table tmp_news;
2、
新建一个临时表
create table tmp_news as select * from news group by nid;
删除原来的表
truncate table youtable;
重命名表
alter table tmp_news rename news;
3、
查找重复的,并且除掉最小的那个。
delete news as a from news as a,
(
select *,min(id) from news group by nid having count(1) > 1
) as b
where a.nid = b.nid and a.id > b.id;
相关文章推荐
- mysql删除重复记录语句的方法
- MySQL之——查询重复记录、删除重复记录方法大全
- MySQL查询重复字段,及删除重复记录的方法
- MySQL查询及删除重复记录的方法
- MYSQL中删除重复记录的方法
- MySQL查询及删除重复记录的方法
- MySQL 数据库中删除重复记录的方法总结
- MySQL查询及删除重复记录的方法
- mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的。 . .
- MySQL删除重复记录的方法
- MySQL查询及删除重复记录的方法
- MYSQL中删除重复记录的方法
- mysql语句删除重复记录的方法
- MySQL 数据库中删除重复记录的方法总结
- MySQL之——查询重复记录、删除重复记录方法大全
- mysql删除重复记录语句的方法
- MYSQL中删除重复记录的方法
- MySQL查询及删除重复记录的方法
- mysql删除重复记录语句的方法
- MYSQL中删除重复记录的方法