title: order sql tree hierarchy
body: <p>What is the best way to sort a table like this:</p>
  
  <pre><code>CREATE TABLE category(
      id INT(10),
      parent_id INT(10),
      name VARCHAR(50)
  );
  
  INSERT INTO category (id, parent_id, name) VALUES
  (1, 0, 'pizza'),        --node 1
  (2, 0, 'burger'),       --node 2
  (3, 0, 'coffee'),       --node 3
  (4, 1, 'piperoni'),     --node 1.1
  (5, 1, 'cheese'),       --node 1.2
  (6, 1, 'vegetariana'),  --node 1.3
  (7, 5, 'extra cheese'); --node 1.2.1
  </code></pre>
  
  <p>To sort it hierarchically by <strong>id</strong> or <strong>name</strong>:<br>
  'pizza' //node 1<br>
  'piperoni' //node 1.1<br>
  'cheese' //node 1.2<br>
  'extra cheese' //node 1.2.1<br>
  'vegetariana' //node  1.3<br>
  'burger' //node 2<br>
  'coffee' //node 3  </p>
  
  <p><strong>EDIT:</strong> the number at the end of the <strong>name</strong> is to visualize the strucutre better, it is not for sorting.</p>
  
  <p><strong>EDIT 2:</strong> as mentioned several times ... the number at the end of the <code>name</code> "cheese <strong>1.2</strong>" was only for visualization purpose, NOT for sorting. I moved them as comments, too many people got confused, sorry.</p>