title: mySQL hierarchical grouping sort
body: <p>I have a schema that essentially looks like this:</p>
  
  <pre><code>CREATE TABLE `data` (
    `id` int(10) unsigned NOT NULL,
    `title` text,
    `type` tinyint(4),
    `parent` int(10)
  )
  </code></pre>
  
  <p>The <code>type</code> field is just an enum where 1 is a parent type, and 2 is a child type (in actuality there are many types, where some should behave like parents and some like children).  The <code>parent</code> field indicates that a record is the child of another record.</p>
  
  <p>I know this is probably not ideal for the query I want to build, but this is what I have to work with.</p>
  
  <p>I would like to sort and group the data so that the parent records are sorted by <code>title</code>, and grouped under each parent is the child records sorted by <code>title</code>.  Like so:</p>
  
  <pre><code> ID | title       |type |parent 
  --------------------------------
   4  | ParentA     | 1   |
   2  | ChildA      | 2   | 4
   5  | ChildB      | 2   | 4
   7  | ParentB     | 1   |
   9  | ChildC      | 2   | 7
   1  | ChildD      | 2   | 7
  </code></pre>
  
  <hr>
  
  <p>** <strong>Edit</strong> **</p>
  
  <p>We should be able to take the <code>type</code> field out of the picture entirely.  If <code>parent</code> is not null then it should be grouped underneath it's parent.</p>