title: SQL - How to Order By in UNION query
body: <p>Is there a way to union two tables, but keep the rows from the first table appearing first in the result set? However orderby column is not in select query</p>
  
  <p>For example:</p>
  
  <p>Table 1</p>
  
  <pre><code>name        surname
  -------------------
  John         Doe
  Bob          Marley
  Ras          Tafari
  </code></pre>
  
  <p>Table 2</p>
  
  <pre><code>name       surname
  ------------------
  Lucky      Dube
  Abby       Arnold
  Result
  </code></pre>
  
  <p>Expected Result:</p>
  
  <pre><code>name        surname
  -------------------
  John         Doe
  Bob          Marley 
  Ras          Tafari
  Lucky      Dube
  Abby       Arnold
  </code></pre>
  
  <p>I am bringing Data by following query</p>
  
  <pre><code>SELECT name,surname FROM TABLE 1 ORDER BY ID  
  UNION  
  SELECT name,surname FROM TABLE 2
  </code></pre>
  
  <p>The above query is not keeping track of order by after union.<br>
  P.S - I dont want to show ID in my select query<br>
  I am getting ORDER BY Column by joining tables. Following is my real query  </p>
  
  <pre><code>  SELECT tbl_Event_Type_Sort_Orders.Appraisal_Event_Type_ID AS Appraisal_Event_Type_ID , ISNULL(tbl_Appraisal_Event_Types.Appraisal_Event_Type_Display_Name, 'UnCategorized') AS  Appraisal_Event_Type_Display_Name 
  INTO #temptbl
  FROM tbl_Event_Type_Sort_Orders 
  INNER JOIN tbl_Appraisal_Event_Types
  ON tbl_Event_Type_Sort_Orders.Appraisal_Event_Type_ID = tbl_Appraisal_Event_Types.Appraisal_Event_Type_ID
  WHERE 1=1
  AND User_Name='abc' 
  ORDER BY tbl_Event_Type_Sort_Orders.Sort_Order
  
  SELECT * FROM #temptbl 
  UNION 
  SELECT DISTINCT (tbl_Appraisal_Event_Types.Appraisal_Event_Type_ID) AS Appraisal_Event_Type_ID , ISNULL(tbl_Appraisal_Event_Types.Appraisal_Event_Type_Display_Name, 'UnCategorized') AS  Appraisal_Event_Type_Display_Name 
  FROM tbl_Appraisal_Event_Types
  INNER JOIN tbl_Appraisal_Events
  ON tbl_Appraisal_Event_Types.Appraisal_Event_Type_ID = tbl_Appraisal_Events.Event_Type_ID
  INNER JOIN tbl_Appraisals 
  ON tbl_Appraisal_Events.Appraisal_ID = tbl_Appraisal_Events.Appraisal_ID
  WHERE 1=1
  AND ((tbl_Appraisals.Assigned_To_Staff_User) = 'abc'  OR (tbl_Appraisals.Assigned_To_Staff_User2) = 'abc' OR (tbl_Appraisals.Assigned_To_Staff_User3) = 'abc')
  </code></pre>