Discuz教程网

mysql 查询第几行到第几行记录的语句

[复制链接]
authicon dly 发表于 2011-9-19 17:18:42 | 显示全部楼层 |阅读模式
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_connect 打开连接慢)
下一篇:MySQL中REPLACE INTO和INSERT INTO的区别分析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 07:03

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表