mysql选择查询

时间:2012-03-31 00:02:56

标签: php mysql

    3717    8   2012-03-30 16:34:17
    3718    10  2012-03-30 16:34:22
    3719    9   2012-03-30 16:34:27
    3720    6   2012-03-30 16:34:32
    3721    7   2012-03-30 16:34:37
        3722    8   2012-03-30 16:34:42
    3723    10  2012-03-30 16:34:47
    3724    5   2012-03-30 16:34:50

我有这个mysql表,我想选择最后10条记录,这是我的代码

SELECT * FROM mach_1 ORDER BY id DESC  LIMIT 10

这就是我得到的

2012-03-30 16:34:50
2012-03-30 16:34:47
2012-03-30 16:34:42
2012-03-30 16:34:37
2012-03-30 16:34:32
2012-03-30 16:34:27
2012-03-30 16:34:22
2012-03-30 16:34:17
2012-03-30 16:34:10
2012-03-30 16:34:05

问题是如何扭转这个

2 个答案:

答案 0 :(得分:3)

尝试这样的事情:

select * from (select * from mach_1 order by id desc 
limit 10) as tbl order by tbl.id;

答案 1 :(得分:1)

很可能你不会绕过嵌套选择:

SELECT * FROM (SELECT * FROM mach_1 ORDER BY id DESC LIMIT 10) AS t ORDER BY t.id ASC

这将首先选择最后10个条目,然后按照您的意愿对它们进行升序排序。