Gebruik Oracle's KEEP LAST
om de beste rc_document_id
. te vinden per document_id
. Verwijder vervolgens alle andere.
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