Hi there, I am kind of a newbie to PHP and I have a question regarding ascending orders.
I am building a point system which is based through MYSQL. It is very similar to a sporting ladder, I will use the following example: name, goals against, goals for, and total points.
Now my question is this: I am able to sort the results of the query via the sortby ascending of the total points, that is fine. But I want to also be able to sort by "goals for" and "goals against" as a secondary sortby incase other teams have the same amount of points.
An example of what I mean is this:
Team goals for goals against total points
team1 3 3 3
team2 7 3 3
team3 10 2 3
So the database will read all three queries, and since the total points is the same, i am looking for a way where it will then sort by "goals for" and then in extreme circumstances, "goals against". So in theory, team3 should be on the top because of their "goals for" is higher than anyone else, and goals against is lower than everyone else.
I had a look around for something similar but to no luck. Maybe there is a simple way around this, although I must be looking in the wrong areas.
Any help regarding this issue will be very much appreciated.
Thanking you all in advance.
Query with multiple ascending orders....
Moderator: General Moderators
-
PhoenixTwo
- Forum Newbie
- Posts: 2
- Joined: Mon Apr 16, 2007 1:45 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You can put them all in the ORDER BY clause, like:
Code: Select all
SELECT * FROM pointsystem ORDER BY `goals against`, `goals for`, `total points`(#10850)
-
PhoenixTwo
- Forum Newbie
- Posts: 2
- Joined: Mon Apr 16, 2007 1:45 am