问题
如下哪两个说法正确:
A.The expressions in the SELECT lists must match in number.
B.Parentheses may not be used to alter the sequence of execution.
C.The data type of each column in the second query must match the data type of its corresponding column in the first query.
D.The ORDER BY clause can be used only once in a compound query, unless a UNION ALL operator is used
解析:答案为A,C
对于集合运算,必须有相同个数的列,数据类型可以不用完全一样,但是要能够互相转换;
括号可以用来改变执行的顺序。
因此 A正确;B说括号可能不改变执行的顺序,因为没有说一定不能,所以保留B选项
;针对C,第二个查询中每个列的数据类型必须与第一个查询中对应列的数据类型匹配,测试发现数据类型还真是必须要一致,否则会报错,我认为C正确,因为我一时没想出反例,但与数据类型可以不用完全一样,但是要能够互相转换不符,所以我保留选C。例如
create table student(
student_id number,
student_name varchar2(10),
faculty_id varchar2(10),
location_id number);
create table faculty(
faculty_id number,
faculty_name varchar2(10),
location_id number);
SELECT faculty_id FROM student
union all
select faculty_id from faculty;
针对D,ORDER BY子句只能在复合查询中使用一次,除非使用UNION ALL运算符,错误,比如
SELECT employee_id, job_id, department_id
FROM employees order by employee_id
UNION all
SELECT employee_id, job_id, department_id
FROM job_history order by employee_id;