2012-11-29 161 views
1

我想顯示按日期添加的升序排序的表格的最後10行。選擇最後的x行

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

注:我需要顯示在反向的結果,最古老的頂部,最新的底部,因此僅僅通過遞減排序不會產生什麼,我需要

這可以在一個查詢中完成嗎?

+0

'訂單的訂單10'。沒有抵消。 –

+0

爲什麼你需要抵消? 'select * from tableName order by dateadded DESC limit 10'不是做你要求的嗎? – Bridge

+0

@ypercube更新的問題,道歉,沒有正確解釋 –

回答

5

只是爲了DESC ...

SELECT * 
FROM tableName 
order by dateadded DESC 
Limit 10 

要通過dateadded DESC極限交換的結果

SELECT * 
FROM (
    SELECT * 
    FROM tableName 
    order by dateadded DESC 
    Limit 10 
    ) r 
ORDER BY dateadded 
+0

謝謝!交換訂單做到了 –