首页 > 代码库 > Oracle 删除重复数据只留一条
Oracle 删除重复数据只留一条
查询及删除重复记录的SQL语句
转自: http://www.cnblogs.com/252e/archive/2012/09/13/2682817.html
select * from ops_service_relate a where (a.SERVICE_ID,a.RELATE_ID,a.RELATE_TYPE) in (select SERVICE_ID,RELATE_ID,RELATE_TYPE from ops_service_relate group by SERVICE_ID,RELATE_ID,RELATE_TYPE having count(*) > 1) and rowid not in (select min(rowid) from ops_service_relate group by SERVICE_ID,RELATE_ID,RELATE_TYPE having count(*)>1)
delete from ops_service_relate a where (a.SERVICE_ID,a.RELATE_ID,a.RELATE_TYPE) in (select SERVICE_ID,RELATE_ID,RELATE_TYPE from ops_service_relate group by SERVICE_ID,RELATE_ID,RELATE_TYPE having count(*) > 1) and rowid not in (select min(rowid) from ops_service_relate group by SERVICE_ID,RELATE_ID,RELATE_TYPE having count(*)>1);
Oracle 删除重复数据只留一条