Wills
Wills

Reputation: 31

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

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?

Upvotes: 1

Views: 223

Answers (4)

DooDoo
DooDoo

Reputation: 13447

you can use

select top 30 * FROM table ORDER BY date ; 

Upvotes: 0

Hasan Fahim
Hasan Fahim

Reputation: 3885

Try the following:

SELECT Top(10) FROM table ORDER BY date ASC    

Upvotes: 0

trickwallett
trickwallett

Reputation: 2468

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.

Upvotes: 1

Arda
Arda

Reputation: 6926

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

Upvotes: 1

Related Questions