Oracle Database SQL — Question 185
Which two statements are true about the ORDER BY clause when used with a SQL statement containing a SET operator such as UNION?
Answer options
- A. Column positions must be used in the ORDER BY clause.
- B. Only column names from the first SELECT statement in the compound query are recognized.
- C. Each SELECT statement in the compound query must have its own ORDER BY clause.
- D. The first column in the first SELECT of the compound query with the UNION operator is used by default to sort output in the absence of an ORDER BY clause.
- E. Each SELECT statement in the compound query can have its own ORDER BY clause.
Correct answer: B, D
Explanation
Option B is correct because in a UNION operation, only the column names from the first SELECT statement are recognized for the ORDER BY clause. Option D is also correct as, without an explicit ORDER BY, sorting defaults to the first column of the first SELECT. The other options are incorrect because they either misstate the requirements for using ORDER BY with UNION or suggest that each SELECT must have its own ORDER BY clause, which is not necessary.