The Little Guy Posted March 10, 2011 Share Posted March 10, 2011 I have a query that looks like so: select b.id, b.name, count(*) as ratings, sum((managers + difficulty + fun + hours + pay + flexibility) / 6) as total from ratings r left join businesses b on(r.business_id = b.id) group by b.name order by total desc limit 10; if I didn't have a limit this could return hundreds of rows, but everything that is returned is what I want, how can I reverse the result set? Basically I want to have a "Top 10" page, that lists the top ten items, but instead of #1 being first, I want it to be last. Quote Link to comment https://forums.phpfreaks.com/topic/230168-reverse-result-set/ Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 Well, you could just iterate through them backwards, or reverse() the recordset. But if you use a subquery, you can re-order them in mysql, too. Quote Link to comment https://forums.phpfreaks.com/topic/230168-reverse-result-set/#findComment-1185336 Share on other sites More sharing options...
The Little Guy Posted March 10, 2011 Author Share Posted March 10, 2011 This works: select * from (select b.id, b.name, count(*) as ratings, sum((managers + difficulty + fun + hours + pay + flexibility) / 6) as total from ratings r left join businesses b on(r.business_id = b.id) group by b.name order by total desc limit 10) as tmp order by tmp.total; Quote Link to comment https://forums.phpfreaks.com/topic/230168-reverse-result-set/#findComment-1185366 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.