I'm starting to learn SQL, learning about views. I was wondering if is possible to join three tables in one view, where some columns will be based on rows from of these tables.
I have three tables:
Roles:
Id | Name | PermissionId
1 | Admin | 1
2 | Staff | 2
RolePermissions:
Id | RoleId | PermissionId
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 1
5 | 2 | 2 <- staff doesn't have permission 3
Permissions:
Id | Name
1 | Perm1
2 | Perm2
3 | Perm3
.
. (not fixed number of permissions)
I would like to create view like this:
Id (of role) | Name | Perm1 | Perm2 | Perm3 ... (not fixed number of columns)
1 | Admin | True | True | True
2 | Staff | True | True | False
Is it possible?