您可以为此使用LIMIT,它用于获取有限数量的记录。让我们首先创建一个表-
mysql> create table DemoTable ( Id int, Name varchar(20) );
使用插入命令在表中插入记录-
mysql> insert into DemoTable values(10,'John'); mysql> insert into DemoTable values(11,'Chris'); mysql> insert into DemoTable values(12,'David'); mysql> insert into DemoTable values(13,'Carol'); mysql> insert into DemoTable values(14,'Mike'); mysql> insert into DemoTable values(15,'Sam'); mysql> insert into DemoTable values(16,'Robert');
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------+--------+ | Id | Name | +------+--------+ | 10 | John | | 11 | Chris | | 12 | David | | 13 | Carol | | 14 | Mike | | 15 | Sam | | 16 | Robert | +------+--------+ 7 rows in set (0.00 sec)
现在让我们选择太多行。下面的查询将跳过前2行并返回4行-
mysql> select *from DemoTable limit 2,4;
这将产生以下输出-
+------+-------+ | Id | Name | +------+-------+ | 12 | David | | 13 | Carol | | 14 | Mike | | 15 | Sam | +------+-------+ 4 rows in set (0.00 sec)