集合运算:
1)union将sql语句中的结果全部输出,而且去重
2)union all效果和union类似,只不过union all不会去重且不会排序
3)intersect 交集
4)minus差集
注意:
1)union取并集的sql语句中必须有相同个数的列,对应列的数据类型必须在相同的数据类型组中(比如numberic 或 character),列的名字可以不一样,union操作对所有的列取并集运算,在检测重复值时空值不会被忽略,默认结果会以升序来显示。
2)intersect返回多个查询语句的交集。多个sql的列的个数和对应列的数据类型一样,对于数据类型能够互相隐式转换也可以,列的名字可以不用一样。修改sql的顺序不会改结果。intersect操作不会忽略空值。
3)order by 子句只会按照第一个select查询中的列来排序。默认,会按照第一个select查询中的第一个列升序排序。
如下哪两个说法正确:
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
答:AC
D错误:order by只能用一次。