title: Insert sorted rows in another table using SQL
body: <p>I am trying to sort a database table and insert sorted rows into another table. However, when I query the new table, it still has unsorted data.</p>
  <pre><code>Create table #unsorted (ID int, dt date)
  Insert into #unsorted values(1, '2019-01-01')
  Insert into #unsorted values(2, '2018-12-15')
  Insert into #unsorted values(3, '2017-01-01')
  
  select * from #unsorted -- unsorted data as expected
  
  Create table #sorted (ID int, dt date)
  
  insert into #sorted 
  select ID, dt from #unsorted Order by dt asc
  
  select * from #sorted -- It should be sorted by date but it is not. 
  </code></pre>
  <p>Expected Result of #sorted  table:</p>
  <pre><code>3   2017-01-01
  2   2018-12-15
  1   2019-01-01
  </code></pre>
  <p>Actual Result of #sorted  table:</p>
  <pre><code>1   2019-01-01
  2   2018-12-15
  3   2017-01-01
  </code></pre>
  <p>How can I physically sort data in the table when inserting into another table?</p>