I have table with sample data as follows
-----------------------------
UserID | ScreenID | rights |
------------------------------
admin 22 0
admin 23 0
admin 24 0
userA 22 1
userA 23 1
userA 24 1
userB 22 0
userB 23 0
userB 24 1
Now I want to fetch 'UserID' and 'rights' details as follows: For each user if the "rights" for all the ScreenIDs are same then that rights value (either '0' or '1') else rights value as 2
That means, required output from the above table should be:
admin , 0
userA , 1
userB ,2
Please help me in writing SQL query for the same. Thanks.