title: Hierarchical queries in MySQL
body: <p>I'm trying to find all the parents, grandparents, etc. of a particular field with any depth. For example, given the below structure, if I provide 5, the values returned should be 1, 2, 3 and 4.</p>
  
  <pre><code>| a  | b  |
  -----------
  | 1  | 2  |
  | 2  | 3  |
  | 3  | 4  |
  | 4  | 5  |
  | 3  | 6  |
  | 4  | 7  |
  </code></pre>
  
  <p>How would I do this?</p>