Hi, Try to change the alias - group is a reserved word and it is causing the syntax error
This one should work SELECT members.name, gr.id, gr.name FROM members LEFT JOIN members AS gr ON gr.id = members.group_id WHERE members.id = 6 Dobromir Velev Web developer http://www.websitepulse.com/ -----Original Message----- From: Keegan Miller <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Date: Saturday, December 29, 2001 08:03 Subject: Syntax error with a JOIN >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 > > --------------------------------------------------------------------- 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