Hi Need help to resolve some complicated query. I'll send the input username (say test ) to the query. I have to list the other users with the same role of the username test and also those usernames should be match with all the groupid of the username test. If the other user has more groups than username test is not an issue, but should match all the groupdid exists in the username test. I tried the following query. It wil return no rows if all the groupids matches. But, I need the username those who have match with all the group id instead of returning no rows for the exact match.
select
group_id
from
user_info us ,group_privilege_details gp
where
login_name='test'
and us.user_id = gp.user_id
EXCEPT
select
group_id
from
user_info u ,group_privilege_details g
where login_name !='test'
and role_id in (select role_id
from user_info
where login_name ='test')
and group_id in (select group_id
from user_info us ,group_privilege_details gp
where login_name='test'
and us.user_id = gp.user_id )
and g.user_id = u.user_id
Thanks in advance. And sorry for long explanation