开发者

SQL Query, getting results from 2 different tables

开发者 https://www.devze.com 2023-01-24 13:30 出处:网络
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 c

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消