3 of 3
added 499 characters in body

Design a way for multiple and single group mapped to a Role?

Currently I am trying to setup a relationship between user groups and roles.

I am trying to satisfy:

  1. Multiple roles apply to single group
  2. multiple groups can have same role
  3. multiple groups with single role.

I have a Group Table with RoleID and GroupName and a Role table with RoleID and RoleName. I am able to satisfy 1 and 2 fine but I am stuck on 3. Say currently I have Group 1 mapped to Roles 1&2. Group 2 mapped to Roles 2. Now lets say I have Role 3 which is ONLY available if I have Group 1 and 2 together.

I dont think my current design can handle checking if a Role is only available if the user belongs to 2 groups vs 1. Is there some SQL I can do or some way to construct the tables?

Ex:

Group Table: Group1:RoleID1 Group2:RoleID2 Group3:RoleID3 HOW TO REPRESENT GROUP1+2 MAP TO RoleID3?

Role Table:

RoleID1:Group1 RoleID2:Group2 RoleID3: Group3 RoleID3:NEED GROUPS 1 AND 2 TOGETHER

For my example above, i can have a Group that maps directly to a Role OR 2 Groups maps to the same Role. So Role3 can be available for a User with Group3 OR Groups1+2. I am not sure how to differentiate the 2. Will i need to redesign the datatables or have update to my SQL?