I have first table like this:
ID Email
100 a@a.com
200 b@b.com
I have second table like this(permissions shared):
ID Assigned ID Role
100 200 Normal user
100 100 Super user
200 200 Normal user
ie. 100 is a super user and can access the sharing features of ID 200.
select t1.ID,t1.email,t2.role from table t1, table t2 where t1.ID=t2.ID;
When I combine both the top 2 tables, i get like this
ID Email Role
100 a@a.com Super user
100 a@a.com Normal user
200 b@b.com Normal user
I want to get output like this:
ID Email Role
100 a@a.com Super user
200 b@b.com Normal user
ie. If any user has a type of super user rights, just take that entry and don’t need the type for normal user.
If the email is already present as super user and further the same email is assigned to someone, then the query should return only for super user.
I even tried using group by and union all:
select t1.ID,t1.email,t2.role from table t1, table t2
where t1.ID=t2.ID group by t1.email having t2.role='Super user'
and not exists ( select t1.ID,t1.email,t2.role from table t1, table t2
where t1.ID=t2.ID group by t1.email having t2.role='Super user')
UNION ALL
select t1.ID,t1.email,t2.role from table t1, table t2
where t1.ID=t2.ID group by t1.email having t2.role<>'Super user';
but seemed to give incorrect answer. Any thoughts?
“If any user has a type of super user rights, just take that entry and don’t need the type for normal user”:
since you don’t need results where users are acting with another role.