删除数据库中的重复记录
SqlServer:
delete from team where id in (select min(id) from team group by [name] having count(id) > 1)
MySql:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[name] having count(id) > 1)' at line 1
(0 ms taken)

so:

create temporary table tmp_wrap select * from users_groups group by uid having count(1>= 1;

truncate table users_groups;

insert into users_groups select * from tmp_wrap;

drop table tmp_wrap;

OR:
delete team as a from team as a,(select min(id) as id,`name` from team group by `name` having count(id) > 1as b where a.id=b.id and a.`name`=b.`name`


posted on 2010-07-09 20:57 Ying-er 阅读(2075) 评论(0)  编辑  收藏 所属分类: MySql

只有注册用户登录后才能发表评论。


网站导航: