应用场景:要显示的数据,一页显示不全,需要分页提交sql请求
特点:要将limit放在查询语句的最后
语法
select 查询列表
from 表
【join type】join 表2
on 连接条件
where 筛选条件
group by 分组字段
having 分组后的筛选
order by 排序的字段
limit 【offset】,size;
offset要显示的条目的起始索引(起始索引从0开始)可省略
size 要显示的条目个数
查询前五条员工信息
select * from employees
limit 0,5;
查询第11条到第25条员工信息
select * from employees limit 10,15;
集合查询
一、union合并:将多条查询语句的结果合并成一个结果
注意事项:
1.两个查询语句查询的列数必须相同,而且列的属性名必须对应相同
2.使用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
如果比较复杂的话用union查询会比较清晰
二、交集运算
语法
select * from student where sdept = 'CS'
intersect
select * from student where sage<=19;
三、差运算
select * from student where sdept = 'CS'
except
select * from student where sage<=19;
四、除运算