对于union查询,就是把多次查询的结果合并起来,形成一个新的查询结果集。
语法
SELECT 字段列表 FROM 表A...
UNION [ALL]
SELECT 字段列表 FROM 表B...;
演示
select * from user where age > 22 union all select * from user where age < 50;

++union all相当于把两次查询的结果合并在一起,而union相当于合并后去重++
select * from user where age > 22
union
select * from user where age < 50;

注:对于联合查询的多张表的列数必须保持一致,字段类型也需要保持一致。
union查询时,在索引列查询速度快