当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Get the null values on permission the role doesn't have

问题描述:

Im trying to do a left join between two sub queries where i would get null values on the permission that the role doesn't have. The query below works but i need a query that i won't have to explicitly define which role i would use in the second subquery.

SELECT DISTINCT a.[APP_Permission_Id],

b.[APP_Permission_Id]

FROM

(SELECT DISTINCT [APP_Permission_Id]

FROM [ADMINS].[APP_ROLE_PERMISSION])a

LEFT JOIN

(SELECT DISTINCT UR.[APP_Role_ID],

RP.[APP_Permission_Id]

FROM [ADMINS].[APP_USER] UU

INNER JOIN [ADMINS].[APP_USER_ROLE] UUR ON UU.[APP_User_Id]=UUR.[APP_User_Id]

INNER JOIN [ADMINS].[APP_ROLE_PERMISSION] RP ON UUR.[APP_Role_ID]=RP.[APP_Role_ID]

INNER JOIN [ADMINS].[APP_ROLE] UR ON RP.[APP_Role_ID]=UR.[APP_Role_ID]

INNER JOIN [ADMINS].[APP_PERMISSION] UP ON RP.[APP_Permission_Id]=UP.[APP_Permission_Id]

WHERE UR.[APP_Role_ID]=1)b

ON a.[APP_Permission_Id]=b.[APP_Permission_Id]

分享给朋友:
您可能感兴趣的文章:
随机阅读: