-
Notifications
You must be signed in to change notification settings - Fork 173
Description
The query works with a LEFT JOIN, but not with a FULL JOIN. The FULL JOIN does not return the rows from matches without any goal scored (in other words, the FULL JOIN returns the same result as the INNER JOIN). Here are the two queries i tried, the first gave the correct answer but not the second :
SELECT mdate, team1,
SUM(CASE
WHEN teamid=team1 THEN 1
ELSE 0
END) AS score1,
team2,
SUM(CASE
WHEN teamid=team2 THEN 1
ELSE 0
END) AS score2
FROM game LEFT JOIN goal ON matchid = id
GROUP BY mdate, team1, team2
ORDER BY mdate, matchid, team1, team2
SELECT mdate, team1,
SUM(CASE
WHEN teamid=team1 THEN 1
ELSE 0
END) AS score1,
team2,
SUM(CASE
WHEN teamid=team2 THEN 1
ELSE 0
END) AS score2
FROM game FULL JOIN goal ON matchid = id
GROUP BY mdate, team1, team2
ORDER BY mdate, matchid, team1, team2