您的位置:首页 > 数据库

关于数据库中重复的记录  的几种取出方法

2007-11-28 16:26 423 查看
--使用distinct关键字查出去重后的记录,并将结果存储在临时表中

select distinct * into #temp from repeat

--删除 repeat 表

delete repeat

--再从临时表中取出所有结果放回repeat表中

insert repeat select * from #temp

--删除临时表

drop table #temp

select * from repeat a

where

(a.userName ) in (select userName from repeat group by userName,userPassword having count(*) > 1)

and

(a.userPassword ) in (select userPassword from repeat group by userName,userPassword having count(*) > 1)



这样取出的是用户名与密码相同的记录!将select改为delete即可删除,当然,这样删除就全部删除了,如果想要留一条,还可在后面加限定条件,来决定留下哪一条!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: