mb81 Posted July 10, 2007 Share Posted July 10, 2007 Hello all, I have a query where I need to get the 10 most recently added lines in a particular MySQL table, but I need to process them starting at the oldest of the 10. Is there a way to reverse the order it returns the rows if I am using a datetime field in DESC order to sort them? I thought about running the whole query, getting the number of rows, and then doing another query to limit to the last 10. I also thought about running the query, then seeking to the 10th to the last row and going from there. Are there any other suggestions or some magic syntax I am missing? Quote Link to comment https://forums.phpfreaks.com/topic/59275-getting-the-most-recent-x-entries-but-shown-in-reverse-order/ Share on other sites More sharing options...
Wildbug Posted July 10, 2007 Share Posted July 10, 2007 You can use a subquery with a LIMIT and reorder it in the outer query. SELECT * FROM (SELECT some, stuff, datecol FROM table ORDER BY datecol DESC LIMIT 10) AS q ORDER BY q.datecol; Quote Link to comment https://forums.phpfreaks.com/topic/59275-getting-the-most-recent-x-entries-but-shown-in-reverse-order/#findComment-294475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.