I'm practicing SQL on SQLZOO, and I'm working on Joins. Question 11 of that section asks: "For every match involving 'POL', show the matchid, date and the number of goals scored."
So I tried the following code:
SELECT matchid, mdate, COUNT(player)
FROM goal JOIN game ON matchid = id
WHERE (team1 = 'POL' OR team2 = 'POL')
GROUP BY matchid
But it throws an error:
'gisq.game.mdate' isn't in GROUP BY
So the answer is:
SELECT matchid, mdate, COUNT(player)
FROM goal JOIN game ON matchid = id
WHERE (team1 = 'POL' OR team2 = 'POL')
GROUP BY matchid, mdate
My question is, why is it required to also include mdate in the GROUP BY clause if it's not part of the aggregate function? Thank you and sorry for the newbie question. Here is the table's format: https://sqlzoo.net/wiki/The_JOIN_operation