开发者

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

开发者 https://www.devze.com 2023-03-11 18:12 出处:网络
This works fine and gives me the most recent results back: SELECT * FROM table ORDER BY date ASC; 开发者_运维百科

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?


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.


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


Try the following:

SELECT Top(10) FROM table ORDER BY date ASC    


you can use

select top 30 * FROM table ORDER BY date ; 
0

精彩评论

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