如何将这两个SQL Blackboard查询组合成一个查询(“和”),以便在控制台上运行以列出所有具有TESTROLE2辅助角色的TESTROLE1?
select user_id from users where institution_roles_pk1 = (select pk1 from institution_roles where role_name = 'TESTROLE1');
select user_id from users where pk1 IN (select users_pk1 from user_roles where institution_roles_pk1 = (select pk1 from institution_roles where role_name = 'TESTROLE2'));
发布于 2014-08-19 21:23:33
您不需要使用user_roles表,因为其他两个表包含执行此查询所需的所有字段:
select u.user_id
from users u, institution_roles ir
where u.institution_roles_pk1 = ir.pk1
and ir.role_name = 'TESTROLE1'
and ir.role_name = 'TESTROLE2';这将为您提供同时具有这两个机构角色的所有用户的列表。
https://stackoverflow.com/questions/22614659
复制相似问题