《Mysql必讀mysql 查詢第幾行到第幾行記錄的語句》要點:
本文介紹了Mysql必讀mysql 查詢第幾行到第幾行記錄的語句,希望對您有用。如果有疑問,可以聯系我們。
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
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/1385.html