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?

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.