oracle去掉重复记录语句(二)
引列即可解决。
www.2cto.com
2、这类重复问题通常要求保留重复记录中的第一条记录,操作方法如下
假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集
select identity(int,1,1) as autoID, * into #Tmp from tableName
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
select * from #Tmp where autoID in(select autoID from #tmp2)
最后一个select即得到了Name,Address不重复的结果集(但多了一个autoID字段,实际写时可以写在select子句中省去此列)
(四)
查询重复
select * from tablename where id in (
select id from tablename
group by id
having count(id) > 1
)
例子
delete from w_m_mjout where ksid in
(select ksid from tableName group by ksid HAVING COUNT(ksid)>1)
and rowid not in (select min(ROWID) from tableName group by ksid HAVING COUNT(ksid)>1)