要选择前10条记录,请在MySQL中使用LIMIT。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> PageNumber text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Page-1'); mysql> insert into DemoTable values('Page-2'); mysql> insert into DemoTable values('Page-3'); mysql> insert into DemoTable values('Page-4'); mysql> insert into DemoTable values('Page-5'); mysql> insert into DemoTable values('Page-6'); mysql> insert into DemoTable values('Page-7'); mysql> insert into DemoTable values('Page-8'); mysql> insert into DemoTable values('Page-9'); mysql> insert into DemoTable values('Page-10'); mysql> insert into DemoTable values('Page-11'); mysql> insert into DemoTable values('Page-12'); mysql> insert into DemoTable values('Page-13'); mysql> insert into DemoTable values('Page-14');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+------------+ | PageNumber | +------------+ | Page-1 | | Page-2 | | Page-3 | | Page-4 | | Page-5 | | Page-6 | | Page-7 | | Page-8 | | Page-9 | | Page-10 | | Page-11 | | Page-12 | | Page-13 | | Page-14 | +------------+ 14 rows in set (0.00 sec)
以下是选择前10条记录的查询-
mysql> select *from DemoTable limit 0,10;
输出结果
这将产生以下输出-
+------------+ | PageNumber | +------------+ | Page-1 | | Page-2 | | Page-3 | | Page-4 | | Page-5 | | Page-6 | | Page-7 | | Page-8 | | Page-9 | | Page-10 | +------------+ 10 rows in set (0.00 sec)