i have a user table and then a user_groups table that references the user table I want to get the list of users that are part of a specific group. I can query the group and get the user_id that is reference, but then I want it to give me that user name that goes whit it. Does anyone know how to write this type of query or do I need to make 2 queries? where the 1st query gets the user_id's from the user_gruops table and the second takes the user_id's and get the user_names from the users table.
Thanks for the help!
Quince
Select query using referential tables...
Moderator: General Moderators
you just need to "join" the two tables. You could do it with an Inner join, or something like this:
Code: Select all
select u.username, g.groupname from users u, groups g where u.id = g.useridI guess I'm still a little confused...
here is what I tried to do:
but where do I relate the user_id?
here is what I tried to do:
Code: Select all
$result = mysql_query("e;SELECT u.username, g.user_id FROM user u, user_group g WHERE user_group="e;group1"e;)Code: Select all
$result = mysql_query("e;SELECT u.username, g.user_id FROM user u, user_group g WHERE g.user_group='group1' and u.id = g.user_id"e;)