联合查询

联合查询:union,union all
对于union查询,就是把多次查询的结果合并起来,形成一个新的结果集
select 字段列表 from 表1 where 条件...
union all
select 字段列表 from 表2 where 条件...;
注意:对于联合查询的多张表的列数,字段类型必须保持一致
union all会将全部的数据直接合并起来,union会对合并后的数据进行去重

代码:
select * from emp where salary>5000
union
select * from emp where age>20; //查询工资大于5000并且年龄大于20的员工

posted @ 2023-04-12 10:23  惊鸿宴远赴人间  阅读(58)  评论(0)    收藏  举报