title: SQL Server Ordering Based on two columns - parent and child
body: <p>I have an ordering problem in SQL Server.</p>
  
  <p>My result set is that of a primary column and a secondary column. The secondary column refers to child nodes of the primary column e.g. it is the id of a primary column that appears later on in the result set</p>
  
  <pre><code>Primary Column | Secondary Column
  1                  NULL
  1                  2
  1                  3
  3                  NULL
  3                  NULL
  2                  NULL
  2                  NULL
  2                  7
  </code></pre>
  
  <p>I need the SQL SELECT to be order by primary column but where there is a secondary column inject the rows related to that id under the primary column e.g. the above result set would look like. </p>
  
  <pre><code>Primary Column | Secondary Column
  1                  NULL
  1                  2
  2                  NULL
  2                  NULL
  2                  7
  1                  3
  3                  NULL
  3                  NULL
  </code></pre>
  
  <p>Is this possible in SQL without using a CURSOR</p>