title: Parent-child ordering in same table
body: <p>I have a table like this-</p>
  
  <pre><code>id  name        ordering    catid 
  1   parent1         1         0
  2   parent2         2         0
  3   parent3         3         0
  4   child11         1         1
  5   child12         2         1
  6   child21         1         2
  7   child22         2         2
  8   child31         1         3
  9   child32         2         3
  </code></pre>
  
  <p>I am trying to get the result like below-</p>
  
  <pre><code>id  name        ordering    catid 
  1   parent1         1         0
  4   child11         1         1
  5   child12         2         1
  2   parent2         2         0
  6   child21         1         2
  7   child22         2         2
  3   parent3         3         0
  8   child31         1         3
  9   child32         2         3
  </code></pre>
  
  <p>I want to order the first <code>parent(catid=0)</code> than its child than second parent and its child.
  Is this possible to achieve desire result with these column.I tried join but not succeeded.
  Surely I am not doing it correctly.
  This is what I have tried-</p>
  
  <pre><code>SELECT a.*,c.name AS category_title FROM table AS a 
  LEFT JOIN table AS c ON c.id = a.catid 
  ORDER BY c.ordering asc, a.ordering asc
  </code></pre>