Page 1 of 1

Ordering mySQL results by two fields

Posted: Sat Oct 24, 2009 6:02 pm
by tomsace
I am wanting to order games on my website in order of the highest rated. My database is something like this:

Game.....Rating.....Number of Votes
game1....4...........7
game2....5...........1
game3....2...........83
game4....5...........7

But if I order by rating game2 would come before game4 but I would like game4 to come before game2 because it is still rated 5/5 but has had more votes. I have tried a few different ways to do this but can't seem to figure it out? I am currently using "ORDER BY Rating DESC".

Thanks alot.
Tom.

Re: Ordering mySQL results by two fields

Posted: Sat Oct 24, 2009 6:12 pm
by requinix
I guess you didn't know you can sort by multiple fields?

Code: Select all

...ORDER BY Rating DESC, Number of Votes DESC
It'll sort those rated best first, but of those with the same rating ones with more votes have precedence.

Re: Ordering mySQL results by two fields

Posted: Sat Oct 31, 2009 9:59 am
by tomsace
Thanks alot got it working perfect.