title: Oracle: Order by Union returning ORA-00933: SQL command not properly ended
body: <p>I have an issue with using Oracle's union and order by clauses together.</p>
  
  <p>I have two complex queries (with sub queries in them) having an order by clause for each of them. I need to union the output of both and return the result. When I run it, I am getting the error ORA-00933: SQL command not properly ended.</p>
  
  <p>But it works when I comment out the order by clauses in both of them.</p>
  
  <p>To test this, I created a simple query as simple as shown below</p>
  
  <pre><code>select * from employee where employee_id=2 order by name
  union
  select * from employee where employee_id=3 order by name;
  </code></pre>
  
  <p>Even this gave the same error when ran with order by clauses but runs well when I commentout the order by clauses.</p>
  
  <p>I tried searching forums, but I could not get solution for the exact problem. I found one at <a href="https://stackoverflow.com/questions/11889518/oracle-query-with-order-by-and-union">ORACLE Query with ORDER BY and UNION</a> but As my queries are already too complecated because of subqueries and joins between too many tables, I dont want to implement this.</p>
  
  <p>Can someone help me on fixing the root cause of the issue.</p>