Reputation: 1859
I have these query results from MenuTable for different User Groups. A user can have more Groups. So, I want to merge the permissions for all the Groups for same PageID the User belongs to. How can I get this done using SQL Query?
First Result:
UserGroupID PageID CanView CanDelete CanEdit
----------------------------------------------------------------------
1 1 0 0 0
1 2 1 1 0
1 3 1 0 0
Second Result
UserGroupID PageID CanView CanDelete CanEdit
----------------------------------------------------------------------
2 1 1 1 1
2 2 0 0 0
2 3 0 0 0
I want to get this Result.
PageID CanView CanDelete CanEdit
------------------------------------------------------------
1 1 1 1
2 1 1 0
3 1 0 0
Upvotes: 0
Views: 39
Reputation: 3202
A simple query like this can do :
SELECT PageID,
MAX(CanView) [CanView],
MAX(CanDelete) [CanDelete],
MAX(CanEdit) [CanEdit]
FROM table
--WHERE UserGroupID in(1,2)
GROUP BY PageID
in addition you can use where clause if you want to look in specific groups (commented condition).
Upvotes: 3