我们通过limit可以限制返回结果的行数

select * from 表名 limit count;
select * from users limit 3;
select * from 表名 limit start,count;
select * from users limit 2,3;
相等
select * from users limit 3 offset 2;
select * from users order by age desc limit 1;
select * from users order by age asc limit 1;
select * from users limit (page-1)*pageSize,pageSize;
当数据查询出来以后,我们可以对数据进行排序处理。在末尾使用order by语句。
select * from 表名 order by 列1 asc|desc,列2 asc|desc,...
注:
- asc即为升序,也是默认值。
- desc即为降序
- 排序首先先按照列1进行排序,如果出现结果相同的,在进行列2排序
select * from users where age > 10 order by id desc;
select * from users where age > 10 order by id asc;