title: simple common table expression to flatten a tree
body: <p>Following is the table format that I have.
  Table name :: USERS</p>
  
  <pre><code>userid reporttouserid
  ------ ------------
  101    NULL
  102    101
  103    102
  </code></pre>
  
  <p>Now I need a query to list all the child user ids under 101 that is 102 and 103 both (103 is indirectly under 101 as its parent 102 is under 101)</p>
  
  <p>I have seen the common table expression in postgresql but not being able to figure out how to go about it.</p>