Created
May 29, 2014 13:29
-
-
Save derekperkins/d61555d00959fc04fe3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
p.user_id, | |
p.workspace_id, | |
p.profile_id, | |
BIT_OR(p.permissions) | |
FROM | |
(SELECT | |
`users_profiles`.`user_id`, | |
NULL AS `team_id`, | |
`profiles`.`id` AS `profile_id`, | |
`profiles` . *, | |
`users_profiles`.`permissions` | |
FROM | |
`nozzleapp`.`profiles` | |
INNER JOIN `nozzleapp`.`users_profiles` ON (`profiles`.`id` = `users_profiles`.`profile_id`) UNION ALL SELECT | |
`TeamUsers`.`user_id`, | |
`teams_profiles`.`team_id`, | |
`profiles`.`id` AS `profile_id`, | |
`profiles` . *, | |
BIT_OR(`teams_profiles`.`permissions`) AS permissions | |
FROM | |
`nozzleapp`.`profiles` | |
INNER JOIN `nozzleapp`.`teams_profiles` ON (`profiles`.`id` = `teams_profiles`.`profile_id`) | |
INNER JOIN `nozzleapp`.`teams_users` AS `TeamUsers` ON (`teams_profiles`.`team_id` = `TeamUsers`.`team_id`)) AS p | |
INNER JOIN | |
`nozzleapp`.`workspaces` AS `Workspace` ON (`Workspace`.`id` = p.workspace_id) | |
INNER JOIN | |
`nozzleapp`.`users_workspaces` AS `UserWorkspaces` ON (`Workspace`.`id` = p.workspace_id) | |
WHERE | |
1 = 1 | |
GROUP BY user_id , workspace_id , profile_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment