Jump to content

Reverse Result Set


The Little Guy

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

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.