Skip to content
Advertisement

Separate user role in SQL

I have a table called user_role_link where the column are userid, roleid, bitlive and bitdeleted. This table links to the dbo.user_role where in here I have columns roleid, DescriptionRole

I want to extract all the users with introleid in (256, 308, 313) but not to be part of this roles: introleid NOT IN (225, 228, 229, 230, 231, 232, 233, 236) normally if you have on of this you could have these ones (256, 308, 313).

So what I am looking to achieve is to remove these roles from the users (256, 308, 313) where they don’t have the main one (225, 228, 229, 230, 231, 232, 233, 236) By mistake someone granted to these users the roles without having the parent one.

My query is like this

Please can you let me know how this can be improved.

Advertisement

Answer

So you want to remove 3 roles from users, but only when any of those other roles don’t exist for them.

Then you could use a NOT EXISTS

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