title: How to get parents of all records in hierarchy table?
body: <p>This is my table in Presto:</p>
  
  <pre><code>ID      ParentId
  ----   ----------
  1       NULL
  2       1
  3       7
  4       2
  5       3
  6       5
  7       NULL
  </code></pre>
  
  <p>I need a query that gives this output:</p>
  
  <pre><code>ID      Root
  ----   ----------
  1       NULL
  2       1
  3       7
  4       1
  5       7
  6       7
  7       NULL
  </code></pre>
  
  <p>For each id show the root (go up the tree branch till finding the root)</p>
  
  <p>How can this be done in Presto SQL ?</p>