Jump to content

ORDER BY ? ASC LIMIT 3 - Display the 3 most recent


TeddyKiller

Recommended Posts

If I had an query with ORDER BY date ASC LIMIT 3. It would display

 

30 minutes ago

10 minutes go

7 minute ago

 

but I want to display the 3 most recent ones in ASC order.. So if it goes like..

 

30 minutes ago

10 minutes go

7 minutes ago

5 minutes ago

3 minutes ago

1 minute ago

 

so If I want to display the 3 most recent ones in ascending order, it'll look like this..

5 minutes ago

3 minutes ago

1 minute ago

 

if you understand.. here is my query. Quite a beast.

$statusq = $db->execute("SELECT c.comment, c.date, u.id, u.avatar, u.displayname FROM `status_comment` as c, `users` as u WHERE c.status_id = '".$row['id']."' AND u.id = c.user_id ORDER BY c.date ASC");

This displays in the order my first one displays... sorry I went in all kinds of order. xD Hopefully you can help me?

Sorry if I didn't make it clear.. if I have these results..

30 minutes ago

10 minutes go

7 minutes ago

5 minutes ago

3 minutes ago

1 minute ago

 

I want to display the 3 most recent ones.. so, 5, 3 and 1. In ascending order... I just can't think how to do it..

Working together we came up with

*$statusq = $db->execute("
SELECT a.* FROM (
SELECT c.comment, c.date, u.id, u.avatar, u.displayname 
FROM `status_comment` as c, `users` as u 
WHERE c.status_id = '".$row['id']."' AND u.id = c.user_id 
ORDER BY c.date DESC LIMIT 3) a
ORDER BY a.date ASC");

 

which works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.