title: How do I order by parent then child?
body: <p>I am trying to write my SQL Server 2008 query in such a way that I can just loop through my output and output headers as needed.  I've done this stuff the wrong way many times and had ColdFusion do the hard work within the page, but need this done in SQL Server. </p>
  
  <pre><code>FeatureID ParentID Feature
  --------------------------
  1         0        Apple      
  2         0        Boy 
  3         2        Charles
  4         1        Daddy
  5         2        Envelope
  6         1        Frankfurter
  </code></pre>
  
  <p>I want my query resultset to look like this:</p>
  
  <pre><code>FeatureID ParentID Feature
  --------------------------
  1         0        Apple      
  4         1        Daddy
  6         1        Frankfurter
  2         0        Boy 
  3         2        Charles
  5         2        Envelope
  </code></pre>
  
  <p>If the ParentID is 0, it means that it's a major category.  If the ParentID is greater than 0, it means it's a minor category, a child of the parent.</p>
  
  <p>So the parents need to be ordered A - Z and the children need to be ordered A-Z.</p>
  
  <p>Can you help me get this ordered correctly?</p>
  
  <pre><code>SELECT FeatureID, ParentID, Feature
  FROM Features
  ORDER BY
  </code></pre>