How can I return 10 of the most recent results in sql?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 14:58:40

问题


This works fine and gives me the most recent results back:

SELECT * FROM table ORDER BY date ASC;

But when I put a limit on it to reduce the results to just 10 of the most recent, it doesn't give me the most recent results:

SELECT * FROM table ORDER BY date ASC LIMIT 30;

How else can I do this?


回答1:


try

SELECT * FROM table ORDER BY date DESC LIMIT 10;

the DESC clause asks for records with the most recent date first. Assuming your date field is a DATETIME-style field, this should work.




回答2:


why don't you order by id (or date) DESC LIMIT 10




回答3:


Try the following:

SELECT Top(10) FROM table ORDER BY date ASC    



回答4:


you can use

select top 30 * FROM table ORDER BY date ; 


来源:https://stackoverflow.com/questions/6262386/how-can-i-return-10-of-the-most-recent-results-in-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!