经典sql

--查找重复记录
select a.* from stu as a,(select name,pwd from stu group by name,pwd having count(*)>1) b where a.name = b.name and a.pwd = b.pwd
--查找未重复记录
select a.* from stu as a,(select name,pwd from stu group by name,pwd having count(*)=1) b where a.name = b.name and a.pwd = b.pwd
--删除重复记录
delete stu where id in(select id from stu as a,(select name,pwd from stu group by name,pwd having count(*)>1) b where a.name = b.name and a.pwd = b.pwd
)
--删除重复记录(保留一条)
select distinct name,pwd into temp from stu
drop table stu
select * into stu from temp
drop table temp

posted on 2010-04-25 12:20  sdh  阅读(120)  评论(0)    收藏  举报

导航