如何在 MySQL 中跳过行?
若要跳过行,请使用 LIMIT OFFSET。我们首先创建一个表 -
mysql> create table DemoTable860( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable860(Name) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable860(Name) values('Robert'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable860(Name) values('David'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable860(Name) values('Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable860(Name) values('Mike'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable860(Name) values('Sam'); Query OK, 1 row affected (0.07 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable860;
这将产生以下输出 -
+----+--------+ | Id | Name | +----+--------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Bob | | 5 | Mike | | 6 | Sam | +----+--------+ 6 rows in set (0.00 sec)
以下是 MySQL 中跳过行的查询 -
mysql> select *from DemoTable860 limit 3 offset 2;
这将产生以下输出 -
+----+-------+ | Id | Name | +----+-------+ | 3 | David | | 4 | Bob | | 5 | Mike | +----+-------+ 3 rows in set (0.00 sec)
广告