Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/230168-reverse-result-set/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/230168-reverse-result-set/#findComment-1185366
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.