查询 student 表中所有数据

1
select * from student

MySQL中使用limit来限制select语句返回记录的条数
limit 可以传入一个或两个参数
limit [位置偏移量],返回数据的数量
位置偏移量是指:查询的开始的位置,例如:第一条数据的偏移量则为 0,第二条数据的偏移量为 1 …….
返回数据的数量:查询数据所返回的记录条数

简单来说就是:

1
select * from student limit a, b

a 指:开始的index位置,从0开始,表示第一条数据
b 指:返回的数据量


查询 student 表中前10条数据(从第一条数据开始,查询10条数据)
1
select * from student limit 10

1
select * from student limit 0, 10

一般情况,limit 用于分页场景
1
2
3
4
5
6
7
8
// 当前的页数 (例如当前为第一页)
int currentPage = 0;

// 每页显示多少条记录 (例如显示每页10条记录)
int pageSize = 10;

//开始的位置(位置偏移量)
int startRow = (currentPage - 1) * pageSize;

数据库limit分页语句
1
select * from student limit startRow, pageSize