As the following query shows, when you include an ORDER
BY clause, it must follow the final SELECT statement and use an integer,
not an identifier, to refer to the ordering column. Ordering takes
place after the set operation is complete.Figure 1: Query
SELECT DISTINCT stock_num, manu_code FROM stock
WHERE unit_price < 25.00
UNION
SELECT stock_num, manu_code FROM items
WHERE quantity > 3
ORDER BY 2;
The compound query above selects the same
rows as Query but
displays them in order of the manufacturer code, as the result shows. Figure 2: Query result