以下是仅显示在范围内设置了LIMIT的前3行的语法-
select *from yourTableName limit yourStartIndex,yourEndIndex;
让我们首先创建一个表-
mysql> create table demo67 −> ( −> id int, −> user_name varchar(40), −> user_country_name varchar(20) −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo67 values(10,'John','US'); mysql> insert into demo67 values(1001,'David','AUS'); mysql> insert into demo67 values(101,'Mike','UK'); mysql> insert into demo67 values(102,'Carol','AUS'); mysql> insert into demo67 values(110,'Chris','US'); mysql> insert into demo67 values(105,'David','AUS');
使用select语句显示表中的记录-
mysql> select *from demo67;
这将产生以下输出-
+------+-----------+-------------------+ | id | user_name | user_country_name | +------+-----------+-------------------+ | 10 | John | US | | 1001 | David | AUS | | 101 | Mike | UK | | 102 | Carol | AUS | | 110 | Chris | US | | 105 | David | AUS | +------+-----------+-------------------+ 6 rows in set (0.00 sec)
这是查询MySQL限制以显示前三行-
mysql> select *from demo67 limit 0,3;
这将产生以下输出-
+------+-----------+-------------------+ | id | user_name | user_country_name | +------+-----------+-------------------+ | 10 | John | US | | 1001 | David | AUS | | 101 | Mike | UK | +------+-----------+-------------------+ 3 rows in set (0.00 sec)