SQL SERVER 中 MySQL LIMIT 子句的等效项?
首先,我们需要创建一个表来了解 limit 子句(正如我们对 SQL 服务器所希望的那样)。我们将借助 CREATE 命令创建一个表。
创建表
mysql> CREATE table limitDemo -> ( -> id int, -> primary key(id) -> ); Query OK, 0 rows affected (0.58 sec)
之后,让我们向表中插入记录 -
mysql> INSERT into limitDemo values(1); Query OK, 1 row affected (0.16 sec) mysql> INSERT into limitDemo values(2); Query OK, 1 row affected (0.12 sec) mysql> INSERT into limitDemo values(3); Query OK, 1 row affected (0.11 sec) mysql> INSERT into limitDemo values(4); Query OK, 1 row affected (0.10 sec) mysql> INSERT into limitDemo values(5); Query OK, 1 row affected (0.12 sec) mysql> INSERT into limitDemo values(6); Query OK, 1 row affected (0.13 sec) mysql> INSERT into limitDemo values(7); Query OK, 1 row affected (0.15 sec) mysql> INSERT into limitDemo values(8); Query OK, 1 row affected (0.09 sec) mysql> INSERT into limitDemo values(9); Query OK, 1 row affected (0.14 sec)
使用 SELECT 语句显示所有记录 -
mysql> SELECT * from limitDemo;
以下为输出
+----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +----+ 9 rows in set (0.00 sec)
让我们看看 limit 子句的查询并从语法开始 -
SELECT column_name1……..N from yourTableName limit integervalue offset integervalue;
现在,我正在应用上述查询 -
mysql> SELECT id from limitDemo limit 5 offset 2;
以下为输出
+----+ | id | +----+ | 3 | | 4 | | 5 | | 6 | | 7 | +----+ 5 rows in set (0.00 sec)
广告