title: SQL get Categories with subcategories
body: <p>Hello I tried to solve and googling how to sort with SQL categories and subcategories to select html element. I didn't found anythink which should worked for me. I have a table <code>categories</code> and it's looks like</p>
  
  <pre><code>id     name       parent
  1      cat1       0
  2      sub1       1
  3      cat2       0
  4      sub2       1
  </code></pre>
  
  <p>My query looks like this</p>
  
  <pre><code>SELECT `a`.*, `b`.* 
  FROM `categories` AS `a`
  LEFT JOIN `categories` AS `b` 
      ON `a`.`id` = `b`.`parent`
  WHERE `a`.`parent` IS NULL  
  </code></pre>
  
  <p>but it's returning me empty array :-/ please help.</p>
  
  <p>I want result like this:</p>
  
  <pre><code>cat1
     sub1
     sub2
  cat2
  </code></pre>