Mutley Posted November 5, 2008 Share Posted November 5, 2008 I have a query that I want to order by a total score. It adds up 4 fields for every user of that team. However it doesn't order them by highest total score, just randomly. $sql = "SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS vr2playerpts, SUM(l.4playerpts) AS vr4playerpts,SUM(l.6playerpts) AS vr6playerpts, SUM(l.8playerpts) AS vr8playerpts, l.wins, l.losses, u.user_id, u.team_id FROM teams t INNER JOIN users u ON u.team_id = t.team_id INNER JOIN leaderboard l ON l.user_id = u.user_id GROUP BY t.team_id ORDER BY (SUM(l.2playerpts) + SUM(l.4playerpts) + SUM(l.6playerpts) + SUM(l.8playerpts)) AND t.level DESC"; Any ideas? I've tried removing the SUM statement and also using the AS statement versions but still seems random. Thanks, Nick. Link to comment https://forums.phpfreaks.com/topic/131534-solved-query-order-wont-work/ Share on other sites More sharing options...
Barand Posted November 5, 2008 Share Posted November 5, 2008 ...ORDER BY (SUM(l.2playerpts) + SUM(l.4playerpts) + SUM(l.6playerpts) + SUM(l.8playerpts)) , t.level DESC Link to comment https://forums.phpfreaks.com/topic/131534-solved-query-order-wont-work/#findComment-683249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.