title: MySQL get parent/child categories in order
body: <p>My question is pretty simple, but I don't know about the answer to it...</p>
  
  <p>I have a table with the following fields and values:</p>
  
  <p>Categories</p>
  
  <pre><code>ID | PARENT_ID | NAME
  ---------------------
   1 |     0     | Cat1
   2 |     0     | Cat2
   3 |     1     | Cat3
   4 |     1     | Cat4
   5 |     3     | Cat5
   6 |     2     | Cat6
   7 |     0     | Cat7
  .....
  </code></pre>
  
  <p>Basically, I need to get the data using MySQL only - sorted by Parent_id. Also, for each Name, I need to add '-' sign depending on the level.<br>
  In the end it should look like this:</p>
  
  <pre><code>ID | PARENT_ID | NAME
  ---------------------
   1 |     0     | Cat1
   3 |     1     | -Cat3
   5 |     3     | --Cat5
   4 |     1     | -Cat4
   2 |     0     | Cat2
   6 |     2     | -Cat6
   7 |     0     | Cat7
  </code></pre>
  
  <p>I don't know how to start building such a query - I was thinking to order by parent_id, but it will not work. </p>
  
  <p>Is there a function or a method that I could use to achieve this? Any hints will by much appreciated.</p>