title: Oracle: sql query for deleting duplicate rows based on a group
body: <p>i need a SQL-Query to delete duplicates from a table. Lets start with my tables</p>
  
  <p><strong>rc_document</strong>: (there are more entries, this is just an example)</p>
  
  <pre><code>+----------------+-------------+----------------------+
  | rc_document_id | document_id | rc_document_group_id |
  +----------------+-------------+----------------------+
  |              1 |           1 |                    1 |
  |              2 |           2 |                    1 |
  |              3 |           3 |                    1 |
  |              4 |           4 |                    1 |
  |              5 |           1 |                    2 |
  |              6 |           3 |                    2 |
  +----------------+-------------+----------------------+
  (document_id can be exists in mulitple rc_document-group´s)
  </code></pre>
  
  <p><strong>rc_document_group</strong>:</p>
  
  <pre><code>+----------------------+----------+
  | rc_document_group_id | priority |
  +----------------------+----------+
  |                    1 |        1 |
  |                    2 |        2 |
  +----------------------+----------+
  </code></pre>
  
  <p>Each rc_document can be joined with the rc_document_group. In the rc_document_group is the priority for each rc_document. </p>
  
  <p>I want to delete the rc_document rows with document_id which have not the highest priority in the rc_document_group. Because the document_id can be exists in multiple rc_document-group´s .. i just want to keep that one, with the highest priority.</p>
  
  <p><strong>here is my expected rc_document table after deleting duplicate document_id´s</strong>:</p>
  
  <pre><code>+----------------+-------------+----------------------+
  | rc_document_id | document_id | rc_document_group_id |
  +----------------+-------------+----------------------+
  |              2 |           2 |                    1 |
  |              4 |           4 |                    1 |
  |              5 |           1 |                    2 |
  |              6 |           3 |                    2 |
  +----------------+-------------+----------------------+
  </code></pre>
  
  <p>the rc_document´s with rc_document_id 1 and 3 must be deleted, because there document_id 1 and 3 are in another rc_document_group with higher priority.</p>
  
  <p>Im new in sql and i have no idea how to write these sql query ... thank for your help!!</p>