oracle实现分页查询
使用伪劣rownum实现分页查询
//可以运行
select rownum from emp where rownum<6;
//不可以运行
select rownum from emp where rownum>6;
//不可以运行,无结果
select rownum from emp where rownum<6 and rownum>3;
//例题 假设每页显示3条,查询出第二页
查不出
select * from (select emp.,rownum from emp) ee where ee.rownum>3 and ee.rownum<7;
可以查出(要给伪列rownum设置别名)
select * from (select emp.,rownum rn from emp) ee where ee.rn>3 and ee.rn<7;
或
select * from (select emp.*,rownum rn from emp) where rn>3 and rn<7;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
在这里插入图片描述
mysql实现分页查询
#查询前五条学生信息
SELECT * FROM students LIMIT 0, 5;
#如果你要查询的数据,是从第一条数据开始的,那么0可以省略,如下:
SELECT * FROM employees LIMIT 5;
#案例2:查询第11条到第25条(起始索引从10开始,显示15条)
SELECT * FROM students LIMIT 10, 15;
使用sql关键字limit
limit 参数1,参数2
参数1 从该位置开始查(不写默认从头开始查)
参数2 查询多少条数据