Question 1
What is the result of executing the following statement? ```sql SELECT last_name, salary FROM employees WHERE dept_id = 10 ORDER BY salary DESC UNION SELECT last_name, salary FROM employees WHERE dept_id = 30 ```
A. It executes successfully: the department 10 rows come back first, sorted by SALARY descending, and the department 30 rows are appended after them in their own order.
This is the "ORDER BY sorts just its own branch" misconception. A component query of a compound query is not an independently ordered result set that then gets concatenated; the set operator combines unordered row sources, so a per-branch ORDER BY has no meaning and Oracle rejects the statement at parse time instead of running it.
B. ORA-03048: SQL reserved word ambiguously used in a compound queryCorrect answer
Correct. In a compound query the ORDER BY clause is legal only after the final component query. Here ORDER BY appears on the first branch and is immediately followed by the UNION keyword, so the parser cannot tell whether the clause belongs to the branch or to the compound query and raises ORA-03048 — the compound-query-specific diagnostic for a reserved word used in an ambiguous position.
C. It executes successfully: Oracle applies the ORDER BY to the whole UNION result, so every row comes back sorted by SALARY descending.
This assumes Oracle silently relocates a misplaced ORDER BY to the end of the compound query. It does not. Placement is part of the syntax: to sort the combined result the clause must be written after the last component query, and until it is the statement does not parse at all.
D. ORA-00933: SQL command not properly ended
ORA-00933 is the generic "unexpected text after a complete statement" error, raised for things like trailing tokens after a single SELECT. Oracle diagnoses a set operator following a branch-level ORDER BY with the more specific compound-query error instead, so this is not the code returned here.
Explanation
A compound query built with UNION, UNION ALL, INTERSECT, or MINUS accepts a single ORDER BY clause, and it must follow the final component query, where it sorts the entire combined result. Writing ORDER BY on an earlier branch and then continuing with a set operator is a parse error, because the parser cannot attach the clause unambiguously. Oracle neither sorts that branch in isolation nor moves the clause to the end for you, so the statement never executes.