开发者

MYSQL show latest few rows, but display the results in an ascending order

开发者 https://www.devze.com 2023-03-16 20:25 出处:网络
I\'m using this query SELECT * FROM notes ORDER BY id DESC LIMIT 3 I开发者_如何学Got shows the latest three notes displayed as follow:

I'm using this query

SELECT * FROM notes ORDER BY id DESC LIMIT 3

I开发者_如何学Got shows the latest three notes displayed as follow: Note 24, Note 23, Note 22

What I'm trying to do is to display the results as follow: Note 22, Note 23, Note 24. Any Ideas ?


Reorder the resulting rows by re-selecting them, but this time use ASC order (the default):

SELECT * 
FROM (SELECT * FROM notes ORDER BY id DESC LIMIT 3) x
ORDER BY id


You can try

SELECT * FROM (SELECT * FROM notes ORDER BY id DESC LIMIT 3)
AS t ORDER BY t.id ASC;
0

精彩评论

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

关注公众号