title: Find Ultimate Parent
body: <p>I'm new to SQL and ran into this problem, the idea is to flatten the hierarchy. This is the input table, where each child has a parent. The objective is to find the ultimate parent.
  Input:</p>
  <pre><code>Parent | Child
  -------|------
  A      | B
  B      | C
  C      | D
  E      | F
  F      | G
  </code></pre>
  <p>Output</p>
  <pre><code>Parent | Child | Ultimate Parent
  -------|------ |----------------
  A      | B     | A
  B      | C     | A
  C      | D     | A
  E      | F     | E
  F      | G     | E
  </code></pre>
  <p>I can't seem to find a way to do this using SQL. Any help appreciated.</p>