MySQL查詢指定行的記錄

2021-07-10 11:58:46 字數 1014 閱讀 3643

1、查詢第一行記錄:

select  *  from

table limit 1;

2、查詢第n行到第m行記錄,或者第n行

-- 2.1 查詢連續的多行記錄(第n~m行)

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

-- 查詢第6行到第15行的記錄

select * from

table limit 5,10;

-----------------------------------------

-- 2.2 查詢第n行

select * from table1 limit n-1,1;

-- 查詢第5行

select * from employee limit 4,1;

-- 查詢第10行

select * from employee limit 9,1;

3、查詢前n行記錄

-- 方法一

select * from table1 limit 0,n;

-- 方法二

select * from table1 limit n;

4、查詢後n行記錄

-- 倒序排序,取前n行 id為自增形式

select * from table1 order

by id desc dlimit n;

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 查詢指定行記錄的語句

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 lim...

oracle中按行查詢指定記錄數

1 輸出表的第一行記錄 select from table name where rownum 1 2 輸出表的前兩行記錄 select from table name where rownum 3 3 輸出表中從 select from select rownum m,a.from table n...

mysql行 MySQL行 記錄 的詳細操作

一 介紹 mysql資料操作 dml 在mysql管理軟體中,可以通過sql語句中的dml語言來實現資料的操作,包括 使用insert實現資料的插入 update實現資料的更新 使用delete實現資料的刪除 使用select查詢資料以及。本節內容包括 插入資料 更新資料 刪除資料 查詢資料 二 插...