SQL Query, getting results from 2 different tables
I have 2 tables, clients and开发者_Python百科 clients_role.
when i enter in a role, i need it to check the clients_role table to see if there are any entries, if there are, get the user_id from the clients_role then match the user_id to the id in the clients table.
Does this make sense?
if anyone could help, it would be great
From what I understood, here it is:
SELECT id FROM clients WHERE id IN (SELECT user_id FROM clients_role WHERE role = "YOURROLE")
Does this work?
select c.*
from clients_role r
inner join clients c
on c.user_id = r.user_id
where r.role = blah
this returns all the clients that have a user_id in the clients_roles tables.
精彩评论