0

Suppose I have a table which contain id(primary key), user-id (foreign key ) and roles( having some roles like USER, ADMIN, SYSTEMADMIN). An user may have multiple roles. I want to find those user only having role USER but not other privileges. I give a snapshot of a similar table. How can I do it.

Image of the table

1 Answer 1

1

You could use a subselect for exclude the userid different from user

select distinct userid from my_table 
where  userid is not in ( select userid from my_table where roles != 'USER')
and roles ='USER'; 

or you can use an having for count(distinct roles)

select userid from my_table
where roles = 'USER' 
having count( distinct roles) = 1
group by userid
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.