Q1.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 clause 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"
Answer:A,C,E
联合查询,使用order by排序的话,以第一个查询的列为准,不能使用第二个查询的列。
解析:union合并的时候,是按照第一条sql语句走的。
A:正确,通过占位符合走的,与列别名没有关系
B:错误,第一条sql没有cust_no
C:正确,2是占位符合,cust_id第一条也存在
D:错误,与B一样的错误
E:正确,第一条sql存在Last Name