码迷,mamicode.com
首页 > 数据库 > 详细

显示查询记录的前n条 mysql limit用法

时间:2015-07-30 19:21:40      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

按时间倒序出所有的数据

mysql> select id,id_no from torder where user = 8  order by createtime desc ;
+----+------------------+
| id | id_no            |
+----+------------------+
| 12 | 2015072609100000 |
| 23 | 2015072816100000 |
| 22 | 2015072816100000 |
| 21 | 2015072816100000 |
| 20 | 2015072815100000 |
| 19 | 2015072815100000 |
| 18 | 2015072814100000 |
| 17 | 2015072810100000 |
| 16 | 2015072810100000 |
| 15 | 2015072720100000 |
| 14 | 2015072720100000 |
| 13 | 2015072609100000 |
| 10 | NULL             |
|  8 | NULL             |
|  7 | NULL             |
|  4 | NULL             |
|  9 | NULL             |
| 11 | 2015072220100000 |
+----+------------------+
18 rows in set

列出其中前5条

mysql> select id,id_no from torder where user = 8 order by createtime desc limit 5;
+----+------------------+
| id | id_no            |
+----+------------------+
| 12 | 2015072609100000 |
| 23 | 2015072816100000 |
| 22 | 2015072816100000 |
| 21 | 2015072816100000 |
| 20 | 2015072815100000 |
+----+------------------+
5 rows in set

 

显示查询记录的前n条 mysql limit用法

标签:

原文地址:http://www.cnblogs.com/leov/p/4690024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!