1

我想显示按添加日期升序排列的表格的最后 10 行。

我知道我可以select count(*) as total from tableName然后$offset = 10 - totalselect * from tableName order by dateadded asc limit 10 offset $offset

注意:我需要反向显示结果,最旧的在顶部,最新的在底部,因此简单地按 desc 排序不会产生我需要的结果

这可以在一个查询中完成吗?

4

1 回答 1

5

只需订购 DESC...

SELECT *
FROM tableName
order by dateadded DESC
Limit 10

交换结果的顺序

SELECT *
FROM (
    SELECT *
    FROM tableName
    order by dateadded DESC
    Limit 10
    ) r
ORDER BY dateadded
于 2012-11-29T15:16:44.453 回答