tags:

views:

23

answers:

1

I have two tables

users - id - name - email

users_groups - user_id - group_id

There are a couple more fields but these are the ones I am trying to grab.

I am trying to return 'id, name, email, group_id'. I think I have the first part of the query right, I just don't understand how do the WHERE statement. Could someone show me the way please?

"SELECT users.name, users.email, users.id, users_group.group_id FROM users, users_group WHERE id='$user_id'"
+2  A: 

You want to use a JOIN statement here. Under the hood that's what your query does already, but actually writing one out is much clearer.

SELECT u.name, u.email, u.id, ug.group_id
FROM users u
INNER JOIN users_groups ug ON ug.user_id = u.id
WHERE u.id = $user_id

(I'm assuming $user_id has properly been escaped previously.)

Aistina
I have made sure the $user_id has been escaped. Thanks for the help, thats perfect.
JasonS