I'm running a query that combines results from three tables, including counting and grouping data. It has player details, tries scored and games played. Currently it returns the player names even if they have zero games played. Is it possible to modify the query so that if a player has zero games they do not appear in the results?
I'm using a left join, but I know that includes results even if there is nothing in one of the columns. Can I get around the problem by using a different join type? I've tried reading up on them and played around with some but can't get the result I want.
SELECT p.`playerID`, p.`playerFirstName`, p.`playerLastName`, IFNULL(g.gamescount,0) as gamescount, IFNULL(t.trycount,0) as trycount FROM players p LEFT JOIN (SELECT playerID, COUNT(*) as gamescount FROM games GROUP BY playerID) as g USING (playerID) LEFT JOIN (SELECT playerID, COUNT(*) as trycount FROM tries GROUP BY playerID) as t USING (playerID) ORDER BY gamescount DESC