In SQL, the ORDER BY clause can appear only once at the end of a compound query (using UNION, INTERSECT, or EXCEPT) to sort the final combined result. The ORDER BY clause accepts column names or aliases defined in the SELECT list. However, you cannot use ORDER BY in the subqueries that are part of set operators - it would only be allowed in the outer query or with TOP/N clauses in some databases.