作者:我是谁的宝贝儿呢颓 | 来源:互联网 | 2014-06-09 00:50
mysql中limit的使用mysql中没有top,替而代之的是limit关键字,具体使用方法如下:mysql>select*fromtest;www.2cto.com+----+------+-----+----------+--------------+|id|name|age|t...
mysql中没有top,替而代之的是limit关键字,具体使用方法如下:
mysql> select * from test;
www.2cto.com
+----+------+-----+----------+--------------+
| id | name | age | tel | address |
+----+------+-----+----------+--------------+
| 1 | aaaa | 12 | aaaaaa | aaaaaaaaa |
| 2 | bbbb | 12 | 12312312 | asgdsf |
| 3 | bbb | 23 | 123423 | asdfsafd |
| 5 | asdf | 23 | asfdsd | asdgesadg |
| 7 | sadf | 23 | asgsdg | asgsdfsafsdf |
+----+------+-----+----------+--------------+
5 rows in set (0.00 sec)
mysql> select * from test limit 2,5
-> ;
+----+------+-----+--------+--------------+
| id | name | age | tel | address |
+----+------+-----+--------+--------------+
| 3 | bbb | 23 | 123423 | asdfsafd |
| 5 | asdf | 23 | asfdsd | asdgesadg |
| 7 | sadf | 23 | asgsdg | asgsdfsafsdf |
+----+------+-----+--------+--------------+
3 rows in set (0.00 sec)
www.2cto.com
mysql> select * from test limit 2,4;
+----+------+-----+--------+--------------+
| id | name | age | tel | address |
+----+------+-----+--------+--------------+
| 3 | bbb | 23 | 123423 | asdfsafd |
| 5 | asdf | 23 | asfdsd | asdgesadg |
| 7 | sadf | 23 | asgsdg | asgsdfsafsdf |
+----+------+-----+--------+--------------+
3 rows in set (0.00 sec)
mysql> select * from test order by name limit 2,4;
+----+------+-----+----------+--------------+
| id | name | age | tel | address |
+----+------+-----+----------+--------------+
| 3 | bbb | 23 | 123423 | asdfsafd |
| 2 | bbbb | 12 | 12312312 | asgdsf |
| 7 | sadf | 23 | asgsdg | asgsdfsafsdf |
+----+------+-----+----------+--------------+
www.2cto.com
3 rows in set (0.00 sec)