mysql 查询第几行到第几行记录的语句
mysql 查询第几行到第几行记录的语句
发布时间:2016-12-29 来源:查字典编辑
摘要:1、查询第一行记录:select*fromtablelimit12、查询第n行到第m行记录select*fromtable1limitn-1...

1、查询第一行记录:

select * from table limit 1

2、查询第n行到第m行记录

select * from table1 limit n-1,m-n;

SELECT * FROM table LIMIT 5,10;返回第6行到第15行的记录

select * from employee limit 3,1; // 返回第4行

3、查询前n行记录

select * from table1 limit 0,n;

select * from table1 limit n;

4、查询后n行记录

select * from table1 order by id desc dlimit n;//倒序排序,取前n行 id为自增形式

5、查询一条记录($id)的下一条记录

select * from table1 where id>$id order by id asc dlimit 1

6、查询一条记录($id)的上一条记录

select * from table1 where id<$id order by id desc dlimit 1

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新mysql数据库学习
热门mysql数据库学习
编程开发子分类