title: Mysql order by parent and child
body: <p>I want to display a result of query sorted by parent and then the child.
  Here's my code</p>
  
  <pre><code>SELECT * FROM 
  mst_category AS parent 
  LEFT JOIN mst_category AS child 
  ON child.category_parent = parent.category_id
  GROUP BY parent.category_id
  ORDER BY parent.category_group, COALESCE(parent.category_parent, parent.category_id), parent.category_parent != 0, child.category_id
  </code></pre>
  
  <p>The result of the query :</p>
  
  <p><a href="https://i.stack.imgur.com/TqaZr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TqaZr.jpg" alt="query result"></a></p>
  
  <p>As you can see some of the children are not sorted by parent id. My question is how to sort it ?</p>