获取前 10 行,然后使用单个 MySQL 查询来显示剩余行记录的语法


我们首先创建一个表 -

mysql> create table DemoTable
(
   Id int
);
Query OK, 0 rows affected (0.71 sec)

使用插入命令在表中插入一些记录 -

mysql> insert into DemoTable values(100);
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable values(101);
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values(102);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(103);
Query OK, 1 row affected (0.64 sec)
mysql> insert into DemoTable values(104);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values(105);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values(106);
Query OK, 1 row affected (0.25 sec)
mysql> insert into DemoTable values(107);
Query OK, 1 row affected (0.44 sec)
mysql> insert into DemoTable values(108);
Query OK, 1 row affected (0.62 sec)
mysql> insert into DemoTable values(109);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values(110);
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable values(111);
Query OK, 1 row affected (0.94 sec)
mysql> insert into DemoTable values(112);
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values(113);
Query OK, 1 row affected (0.35 sec)
mysql> insert into DemoTable values(114);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(115);
Query OK, 1 row affected (0.25 sec)

使用 select 语句从表中显示所有记录 -

mysql> select *from DemoTable;

这将生成以下输出 -

+------+
| Id   |
+------+
|  100 |
|  101 |
|  102 |
|  103 |
|  104 |
|  105 |
|  106 |
|  107 |
|  108 |
|  109 |
|  110 |
|  111 |
|  112 |
|  113 |
|  114 |
|  115 |
+------+
16 rows in set (0.00 sec)

以下是获取前 10 行以及剩余行的查询 -

mysql> select *from DemoTable LIMIT 999 offset 0;

这将生成以下输出 -

+------+
| Id   |
+------+
|  100 |
|  101 |
|  102 |
|  103 |
|  104 |
|  105 |
|  106 |
|  107 |
|  108 |
|  109 |
|  110 |
|  111 |
|  112 |
|  113 |
|  114 |
|  115 |
+------+
16 rows in set (0.00 sec)

更新于: 01-10-2019

134 浏览

开启你的职业生涯 之旅

完成课程并获得认证

立刻开始
广告