本教程中所使用的数据库的建表语句都在“SQL教程——索引”这篇文章中,点击链接直达:索引&建表语句
摘要:本文主要介绍SQL的子查询分页
联合查询
union联合 合并:将多条查询语句的结果合并成一条结果
语法:
select ...
union
select ...
union
...
特点:
-
要求多条查询语句的查询列数是一致的!
-
要求多条查询语句的查询的每一列的类型和顺序最好一致!
-
union关键字默认去重,如果使用union all可以包含去重项!
#引入案例:查询部门编号>90或邮箱包含a的员工的员工信息
select * from employees where email like '%a%' or department_id > 90;
select * from employees where email like '%a%'
union
select * from employees where department_id > 90;