I'm pulling my hair out about a query that should be simple. I have a
table "members" with columns id, group_id, and a few more that aren't
important here. group_id refers to another row in the same "members"
table, but not all members have a group_id. What I want to do is
select, for a particular member, the member's name and (if the member is
in a group) the group's ID and name.
Here's the simplified query:
SELECT members.name, group.id, group.name
FROM members
LEFT JOIN members AS group
ON group.id = members.group_id
WHERE members.id = 6
And here's the error I get:
You have an error in your SQL syntax near 'group ON group.id =
members.group_id WHERE members.id = 6' at line 3
Can anybody explain to me how I can get this to work? Is there some
kind of trick to joining a table to itself?
Thanks,
Keegan Miller
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php