title: SQL - UNION, priority on the first select statement when doing order by
body: <p>I'm trying to print out the results from the "GermanDB" Database first, while also showing everything from the Boston DB that was not in the German database. Can this be done in one query?</p>
  
  <p>My query (the bold part functions but does not order the way I want)</p>
  
  <pre><code>select * from (  
  SELECT DISTINCT a.ProductRef  
  FROM GERMANDB.dbo.LOCATIONS AS a INNER JOIN GERMANDB.dbo.ITEMS AS b ON a.ProductRef =   b.ProductRef   
  WHERE b.ACTIVE=1  
  ) ta  
  UNION select * from  
  SELECT DISTINCT c.ProductRef  
  FROM BOSTONDB.dbo.LOCATIONS AS c INNER JOIN BOSTONDB.dbo.ITEMS AS d ON c.ProductRef =   d.ProductRef   
  WHERE c.ACTIVE=1 (c.ProductRef NOT IN   
  (SELECT ProductRef FROM GERMANDB.dbo.ITEMS where ACTIVE=1))  
  ) tb  
  order by ta.ProductRef** , tb.productRef
  </code></pre>