title: SQL recursive query on self referencing table (Oracle)
body: <p>Lets assume I have this sample data:</p>
  
  <pre><code>| Name     | ID | PARENT_ID |
  -----------------------------
  | a1       | 1  | null      |
  | b2       | 2  | null      |
  | c3       | 3  | null      |
  | a1.d4    | 4  | 1         |
  | a1.e5    | 5  | 1         |
  | a1.d4.f6 | 6  | 4         |
  | a1.d4.g7 | 7  | 4         |
  | a1.e5.h8 | 8  | 5         |
  | a2.i9    | 9  | 2         |
  | a2.i9.j10| 10 | 9         |
  </code></pre>
  
  <p>I would like to select all records start from accountId = 1, so the expected result would be:</p>
  
  <pre><code>| Name     | ID | PARENT_NAME | PARENT_ID | 
  -------------------------------------------
  | a1       | 1  | null        | null      |
  | a1.d4    | 4  | a1          | 1         |
  | a1.e5    | 5  | a1          | 1         |
  | a1.d4.f6 | 6  | a1.d4       | 4         |
  | a1.d4.g7 | 7  | a1.d4       | 4         |
  | a1.e5.h8 | 8  | a1.e5       | 5         |
  </code></pre>
  
  <p>I am currently able to make the recursive select, but then I can't access the data from the parent reference, hence I can't return parent_name. The code I'm using is (adapted to the simplistic example):</p>
  
  <pre><code>SELECT id, parent_id, name
  FROM tbl 
    START WITH id = 1 
    CONNECT BY PRIOR id = parent_id
  </code></pre>
  
  <p>What SQL should I be using to the mentioned above retrieval?</p>
  
  <p><em>Additional key words for future seekers: SQL to select hierarchical data represented by parent keys in same table</em></p>