mysql 查詢第幾行到第幾行記錄的語句
更新時間:2011年07月01日 01:28:21 作者:
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
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
相關(guān)文章
MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能
這篇文章主要介紹了 MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能的相關(guān)資料,需要的朋友可以參考下2017-02-02
MySQL與PHP的基礎(chǔ)與應(yīng)用專題之索引
MySQL是一個關(guān)系型數(shù)據(jù)庫管理系統(tǒng),由瑞典MySQL?AB?公司開發(fā),屬于?Oracle?旗下產(chǎn)品。MySQL?是最流行的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)之一,本系列將帶你掌握php與mysql的基礎(chǔ)應(yīng)用,本篇從索引開始2022-02-02

