How to use ORDER BY clause in SET operations

Here is  a small description of how to use the ORDER BY clause in any of the SET operations.
 
In such a type of query that has a compounded SELECT statement, the ORDER BY clause can appear only once at the end of the query. In this, the sorting is done on the basis of a column which is present in the first query only.
Here in the example mentioned below the query is using the compound "SELECT" that unifies the result from two customers and the sorting is done on the basis of "Price".
 
EXAMPLE:
 

SELECT Item_id, Item_name, Price

FROM Orders

WHERE Customer_id=1110

UNION

SELECT Item_id, Item_name, Price

FROM Orders

WHERE Customer_id=1120

ORDER BY 2;

Ebook Download
View all
Learn
View all
F11Research & Development, LLC