title: How to optimize mysql query getting categories and subcategories
body: <p>I created a script which builds a menu with categories, sub-categories and sub-sub-categories. 
  To get these items I use 3 separate MySQL queries. As follows:</p>
  
  <p>To retrieve the main categories:</p>
  
  <pre><code>SELECT id, name FROM categories WHERE parent_id=0
  </code></pre>
  
  <p>To retrieve the sub-categories for each category I use:</p>
  
  <pre><code>SELECT id, name FROM categories WHERE parent_id=?
  </code></pre>
  
  <p>Where the ? is the id of the parent category.
  I then run the query again for each sub-category.</p>
  
  <p>How can I optimise this script to use less sql queries ?
  Thank you in advance.</p>