title: Hierarchical multiple update query on one table - oracle
body: <p>I have a table <i>person</i> with these columns, dependent on each other.</p>
  
  <pre><code>person_id, related_person_id, beginner_related_person_id 
  </code></pre>
  
  <p>Example of my data</p>
  
  <pre><code>person_id related_person_id beginner_related_person_id 
  1         null              null
  2         1                 null
  3         2                 null
  4         null              null
  5         4                 null 
  6         null              null
  </code></pre>
  
  <p>This column beginner_related_person_id is new and for now null. </p>
  
  <p>I have to update this row with values from person_id, but the root person_id.</p>
  
  <pre><code>person_id related_person_id beginner_related_person_id
  1         null              null
  2         1                 1
  3         2                 1
  4         null              null
  5         4                 4 
  6         null              null
  </code></pre>
  
  <p>I have started to write my query but need a hint.</p>
  
  <pre><code>update person
  set beginner_related_person_id = person_id
  where person_id in (select  distinct person_id from person start with  related_person_id in (select person_id from person)
    connect by prior beginner_person_id = person_id);
  </code></pre>
  
  <p>Should I use loops? Or something else?</p>