QuestionQ105

VerifiedRestricting and Sorting Data

Review this SQL statement:

SELECT cust_id, cust_last_name `Last Name`  
  
FROM customers -  
  
WHERE country_id = 10 -  
  
UNION -  
  
SELECT cust_id CUST_NO, cust_last_name  
  
FROM customers -  
  
WHERE country_id = 30 -  

Identify three ORDER BY clauses, any one of which can successfully complete the query.

Choose three
Explanation

For a UNION compound query, Oracle applies the final ORDER BY to the complete result set and permits select-list positions or result-column names/aliases. The first SELECT defines the result-column names: CUST_ID and the quoted alias "Last Name". Thus the quoted second-column alias, the positional ordering 2, 1, and 2, cust_id are valid. CUST_NO is an alias only in the second SELECT and is not a result-column name of the compound query.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!