Daney11 Posted January 26, 2007 Share Posted January 26, 2007 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.ThanksDane Link to comment https://forums.phpfreaks.com/topic/35818-solved-order-by/ Share on other sites More sharing options...
matfish Posted January 26, 2007 Share Posted January 26, 2007 Google GROUP BY Link to comment https://forums.phpfreaks.com/topic/35818-solved-order-by/#findComment-169813 Share on other sites More sharing options...
Psycho Posted January 26, 2007 Share Posted January 26, 2007 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 More sharing options...
Daney11 Posted January 26, 2007 Author Share Posted January 26, 2007 Works perfect, thanks mjdamato Link to comment https://forums.phpfreaks.com/topic/35818-solved-order-by/#findComment-169826 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.