정렬 순서를 변경해 데이터를 추출하려면 코드 3-11과 같이 UNION 쿼리의 마지막 SELECT 문에 ORDER BY 절을 추가한다.
코드 3-11 UNION 쿼리에 정렬 순서 명시
SELECT Category, ‘Oct’ AS SalesMonth, OctQuantity AS Quantity,
OctSales AS SalesAmt
FROM SalesSummary
UNION
SELECT Category, ‘Nov’, NovQuantity, NovSales
FROM SalesSummary
UNION
SELECT Category, ‘Dec’, DecQuantity, DecSales
FROM SalesSummary
UNION
SELECT Category, ‘Jan’, JanQuantity, JanSales
FROM SalesSummary
UNION
SELECT Category, ‘Feb’, FebQuantity, FebSales
FROM SalesSummary
ORDER BY SalesMonth, Category;