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);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。