For example, some actions that users can do, require a set of permissions.
Users are stored in the Users table:
UserId |
---|
1 |
2 |
and permissions in the Permissions table. Users can have permission A, B, or both.
UserId | Permission |
---|---|
1 | A |
1 | B |
2 | A |
Required permissions are stored in RequiredPermissions. From this, the POST action requires both permissions A and B
ActionType | Permission |
---|---|
POST | A |
POST | B |
GET | B |
I want to query all users that can POST (user 1). This query would give users that have any permissions (that is, user 1 and 2):
select distinct u.UserId
from Users as u
join RequiredPermissions as rp
on rp.ActionType = "POST"
join Permissions as p
on u.UserId = p.UserId
How do I query users which have both permissions A and B with this schema?