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'"
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.
(I’m assuming
$user_idhas properly been escaped previously.)