开发者

Mysql limit order by question

I have this query: SELECT * FROM mash order by id asc开发者_如何学Go limit 10

but what i'm attempting to do is select the last 10 records inserted but order by id asc.

So say the data is: 13,4,4,5,6,78,4,23,21,1,1,2,3,4,5,65,6,7,3 and "3" was the last record inserted, how could i select 1,1,2,3,4,5,65,6,7,3 from it?


I think the best you ca do is

select * from (select * from mash order by creation desc limit 10) s order by s.id


select * from (select * from mash order by id desc limit 10) order by id

assuming ID is your monotonically increasing record of insertion (as it usually is).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜