Jump to content

[SOLVED] Order By


Daney11

Recommended Posts

Hey guys,

How would i go about using a mysql query and order by in this way..

i want it to order by 2 values..... team points and goal difference.

I want the team points and primary and if team points are the same i want the goal difference to kick in.

My query is

$strQuery = "SELECT * FROM teams WHERE team_league = '1' ORDER BY team_points ASC";
$result = mysql_query($strQuery,$db) or die(mysql_error());

It works fine and the team with the highest points are at the top. But if 3 or 4 teams have the same points i want the 'team_goaldifference' row with the highest goaldifference to be at the top.

Thanks

Dane
Link to comment
https://forums.phpfreaks.com/topic/35818-solved-order-by/
Share on other sites

No, you do not want GROUP BY. GROUP BY will "collapse" multiple records into single records. You just need to use two ORDER BY values.

$strQuery = "SELECT *
                  FROM teams
                  WHERE team_league = '1'
                  ORDER BY team_points ASC, goal_difference";
$result = mysql_query($strQuery,$db) or die(mysql_error());
Link to comment
https://forums.phpfreaks.com/topic/35818-solved-order-by/#findComment-169818
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.