I have the following SQL with a JOIN, if I run this, it ignores records that have NULL values in the group_id in the users table. Therefore, I get less results
SELECT u.user_id, u.email, g.group_name
FROM users u
JOIN groups g USING (group_id)
WHERE u.year=2017
However, If I run it without the JOIN like this:
SELECT u.user_id, u.email
FROM users u
WHERE u.year=2017
Then it gives all the users I need. Some of the users do not have the group_id set as this is not a required field. Is there a way to JOIN the NULL values too? Do I nee to have a NULL value in the groups table? This would not be possible as my group_id field in the groups table is NOT NULL and PRIMARY KEY