Evaluate the following SQL statement:
SQL> 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;
Which ORDER BY clauses are valid for the above query? (Choose all that apply.)
A.
ORDER BY 2,1
B.
ORDER BY CUST_NO
C.
ORDER BY 2,cust_id
D.
ORDER BY "CUST_NO"
E.
ORDER BY "Last Name"
Why are B and D wrong and E correct.
You are allowed to sort the data using the column names only from FIRST select in that case:
SELECT cust_id, cust_last_name “Last Name”
And B – cust_no is not a part of that select, so B is wrong
D – “cust_no” – the same, not a part of first select
E – Correct – 😉 Is used is first select
Is that clear now for you?
Thanks bro
Is an alias allowed in Order By ?
yep!