I have the following two tables (simplified for this question):
CREATE TABLE team (
teamID CHAR(6) NOT NULL PRIMARY KEY);
CREATE TABLE member (
memberID CHAR(7) NOT NULL PRIMARY KEY,
teamID CHAR(6) NOT NULL REFERENCES team(teamID) );
I also have the following query, which is to list the number of members in each team:
SELECT teamID, count(memberID) AS [noOfMembers]
FROM member
GROUP by teamID;
However, I have four teams (MRT1, MRT2, MRT3 and MRT4). My members in my table only belong to teams 2 and 3, so when I run the query I get the following output:
MRT2: 7, MRT3: 14
I'm not sure how I can adjust my query to list all 4 teams like so:
MRT1: 0, MRT2: 7, MRT3: 14, MRT4: 0
I have been messing with subqueries to fix this without any luck. Any ideas? Thanks