Mr Chris Posted August 29, 2007 Share Posted August 29, 2007 Hi Guys, I have a table join that works fine which lists goalscorers in a football season: SELECT th.team_id, th.team_name AS team, th.league, re.report_id, re.competition, s.player_id AS player, s.report_id, players.player_name, players.position, SUM( s.goals ) AS total_goals FROM player_stats s INNER JOIN teams th ON th.team_id = players.team_id INNER JOIN reports re ON re.report_id = s.report_id LEFT OUTER JOIN players ON players.player_id = s.player_id WHERE re.competition = '$x' GROUP BY players.player_id ORDER BY total_goals DESC However on the count query; players.position, SUM( s.goals ) AS total_goals it also outputs all players in the database even if they have scored no/zero goals. Which I don't want. I only want a list of players who have scored goals So I want to add in the line something like: WHERE total_goals !='' Somewhere in my code to achieve this - Can anyone help? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/67200-simple-count-query-help/ Share on other sites More sharing options...
Illusion Posted August 29, 2007 Share Posted August 29, 2007 GROUP BY players.player_id HAVING total_goals>0 ORDER BY total_goals DESC Link to comment https://forums.phpfreaks.com/topic/67200-simple-count-query-help/#findComment-337127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.