Titling SQL questions is hard! Feel free to change it if you can think how to describe this better!
I have a pretty typical set up: 3 tables, users
, groups
, and group_members
.
Here's an SQL Fiddle: http://sqlfiddle.com/#!2/23712/1
What I want to know is which groups are which users in.
So, I'm running:
SELECT u.id, u.firstname, u.lastname,
GROUP_CONCAT(m.group_id) as groups
FROM group_members m, users u
WHERE m.user_id = u.id
GROUP BY id
ORDER BY u.lastname ASC
Which is cool, and shows me the users name and what groups they are in.
My problem is that users who aren't in any groups don't show up, as of course the WHERE bit doesn't match them.
How can I also return the users who aren't in any group? (In the SQL Fiddle above, I want another row for Zack Jones, showing that he is either in group 0, or NULL or something!)