Skip to content
Advertisement

sql query: return a list that will contain the users / groups who will have access to an application

I’m doing an sql query where I want to return a list that will contain the users / groups who will have access to an application. This is the scheme, we will see if a user have permissions, if not, we going to see the group. If both not, we see if there are any permissions on the application, if not, then will add the user to the permissions, if the user or group have permissions we add to.

-Edit- Table Schema

Advertisement

Answer

Took the liberty of aliasing the tables for readability:

If I understand correctly, sounds like we want to return a list of users who either have direct permission on the app, or who are members of a group with permission on the app.

Let’s simplify it by doing those two queries separately:

Might have to play with that a little to get exactly what you need, but I would say: do them separately. Might not even need the join to the User_Master table, since it doesn’t look like you’re actually retrieving any fields from it. Just filter from ap.UserMasterID or g.UserMasterID.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement