您的位置:首页 > 数据库 > MySQL

mysql中limit使用

2012-10-12 00:00 218 查看
mysql中没有top,替而代之的是limit关键字,具体使用方法如下:

mysql> select * from test;

+----+------+-----+----------+--------------+

| 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)

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 |

+----+------+-----+----------+--------------+

3 rows in set (0.00 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql中limit使用