limit MySQL

1.语法

  • select column_name(s) from table_name limit [M] N;
  • select column_name(s) from table_name limit N offset M

(1) M:返回结果的偏移量。即跳过M条数据,从第M+1条数据开始取起。M可以不取,此时默认是0。

(2) N:返回结果的数据条数。即返回N条数据。

(3) limit [M] N:跳过M条数据,取M+1至M+N条数据。

2.示例

mysql> select * from limit_demo;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+----+

(1) mysql> select * from limit_demo limit 7,1;

+----+
| id |
+----+
| 8 |
+----+
1 row in set

(2) mysql> select * from limit_demo limit 7,2;
+----+
| id |
+----+
| 8 |
| 9 |
+----+
2 rows in set

(3) mysql> select * from limit_demo limit 7;

+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
+----+
7 rows in set

(4) mysql> select * from limit_demo limit 7 offset 1;
+----+
| id |
+----+
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+----+
7 rows in set

posted @ 2019-07-18 12:03  aczy  阅读(218)  评论(0编辑  收藏  举报