我想显示按日期添加升序排序的表格的最后10行。
我知道我可以select count(*) as total from tableName
和$offset = 10 - total
然后select * from tableName order by dateadded asc limit 10 offset $offset
注意:我需要反向显示结果,顶部最旧,底部最新,因此只需按desc排序就不会产生我需要的结果
这可以在一个查询中完成吗?
答案 0 :(得分: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