Verwenden Sie Oracles KEEP LAST
um die beste rc_document_id
zu finden pro document_id
. Dann alle anderen löschen.
delete from rc_document
where rc_document_id not in
(
select max(d.rc_document_id) keep (dense_rank last order by dg.priority)
from rc_document d
join rc_document_group dg using (rc_document_group_id)
group by d.document_id
);
Rextester-Demo:http://rextester.com/NZVZGF52818