union子句
union操作符将两个查询结果合并为一个结果集。为连接查询
合并两个表时:列的数日和顺序在查中必须一致;数据类型兼容
语法:
select
?语句
union
?
[
all
]
select
?语句
注意:
1
.union运算从最终结果集中删除重复记录,如想不删除重复记录使用all关键字
2
.第一个select语句中不能用order?by或compute子句,只能是最后一个select语名后用
例:查询计算机系的学生式年龄不大于19岁的学习,按年龄倒排序
select
?
*
?
from
?department?
where
?dept
=
'
computer
'
;
union
;
selrct?
*
?
from
?student?
where
?age
<=
19
order
?
by
?age?
desc
注:两表中字段一致,