要跳过前10个结果,请使用“极限偏移”。语法如下-
select *from yourTableName limit 10 offset lastValue;
让我们创建一个表来了解上述语法。以下是创建表的查询-
mysql> create table SkipFirstTenRecords −> ( −> StudentId int, −> StudentName varchar(200) −> );
现在,您可以借助insert命令在表中插入一些记录。查询如下-
mysql> insert into SkipFirstTenRecords values(100,'John'); mysql> insert into SkipFirstTenRecords values(101,'Johnson'); mysql> insert into SkipFirstTenRecords values(102,'Carol'); mysql> insert into SkipFirstTenRecords values(103,'Smith'); mysql> insert into SkipFirstTenRecords values(104,'Bob'); mysql> insert into SkipFirstTenRecords values(105,'David'); mysql> insert into SkipFirstTenRecords values(106,'Sam'); mysql> insert into SkipFirstTenRecords values(107,'Taylor'); mysql> insert into SkipFirstTenRecords values(108,'Ramit'); mysql> insert into SkipFirstTenRecords values(109,'Belly'); mysql> insert into SkipFirstTenRecords values(110,'Aaron '); mysql> insert into SkipFirstTenRecords values(111,'Peter'); mysql> insert into SkipFirstTenRecords values(112,'Travis'); mysql> insert into SkipFirstTenRecords values(113,'Alex'); mysql> insert into SkipFirstTenRecords values(114,'Pat '); Display all records which I have inserted in the table. The query is as follows: mysql> select *from SkipFirstTenRecords;
以下是输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 100 | John | | 101 | Johnson | | 102 | Carol | | 103 | Smith | | 104 | Bob | | 105 | David | | 106 | Sam | | 107 | Taylor | | 108 | Ramit | | 109 | Belly | | 110 | Aaron | | 111 | Peter | | 112 | Travis | | 113 | Alex | | 114 | Pat | +-----------+-------------+ 15 rows in set (0.00 sec)
跳过上表中的前10条记录的查询全部如下-
mysql> select *from SkipFirstTenRecords limit 10 offset 10;
以下是自我们跳过前10条记录以来的输出,仅显示最后5条记录-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 110 | Aaron | | 111 | Peter | | 112 | Travis | | 113 | Alex | | 114 | Pat | +-----------+-------------+ 5 rows in set (0.00 sec)