title: SQL Group By and return pairs from list
body: <p>Sorry if the title doesn't match this content.</p>
  <p>I currently have a database that has a list of schedules and the places it travels through.</p>
  <pre><code>HeaderId, LocationOrdinal, Location
  1,0,A
  1,1,B
  1,2,C
  1,3,D
  1,4,E
  
  2,0,A
  2,1,B
  2,2,F
  2,3,G
  </code></pre>
  <p>I would like to have them grouped by HeaderId, have the locations next to each other and then distinct.</p>
  <pre><code>Desired Output
  A,B
  B,C
  C,D
  D,E
  B,F
  F,G
  </code></pre>
  <p>Note that A,B is only in there once.</p>
  <p>I currently get all the values in the table and do it via C#, but it's very slow.</p>
  <p>SELECT HeaderId, Location FROM [dbo].[sched_timings] ORDER BY HeaderId, LocationOrdinal</p>
  <p>Thanks in advance</p>