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)文章
CentOS6.9下mysql 5.7.17安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了CentOS6.9下mysql 5.7.17安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10Mysql數(shù)據(jù)庫名和表名在不同系統(tǒng)下的大小寫敏感問題
在 MySQL 中,數(shù)據(jù)庫和表對應(yīng)于那些目錄下的目錄和文件。因而,操作系統(tǒng)的敏感性決定數(shù)據(jù)庫和表命名的大小寫敏感。2011-01-01mysql數(shù)據(jù)類型和字段屬性原理與用法詳解
這篇文章主要介紹了mysql數(shù)據(jù)類型和字段屬性,結(jié)合實例形式分析了mysql數(shù)據(jù)類型和字段屬性基本概念、原理、分類、用法及操作注意事項,需要的朋友可以參考下2020-04-04MySQL腳本批量自動插入數(shù)據(jù)及數(shù)據(jù)可按條件插入實現(xiàn)
在初始化數(shù)據(jù)庫或者導(dǎo)入一些數(shù)據(jù)時,常常會用到批量的操作,本文主要介紹了MySQL腳本批量自動插入數(shù)據(jù)及數(shù)據(jù)可按條件插入實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2024-01-01MySQL學(xué)習(xí)之事務(wù)與并發(fā)控制
這篇文章主要介紹了MySQL中的事務(wù)與并發(fā)控制,一個事務(wù)可以理解為一組操作,這一組操作要么全部執(zhí)行,要么全部不執(zhí)行,想了解更多的小伙伴,可以參考閱讀本文2023-03-03