Rewrite subquery (not in) as Join
Hello everyone, you can rewrite the request:
select userid from User where userid not in(select userid from UserRole where roleid in(8));
as Join?
the problem is that one user can have multiple roles
thanks in advance.
mysql> desc User; + -------------------- + ------------------- + ------ + - ---- + --------- + ---------------- + | Field | Type | Null | Key | Default | Extra | + -------------------- + ------------------- + ------ + - ---- + --------- + ---------------- + | userId | int (11) | NO | PRI | NULL | auto_increment | | userName | varchar (50) | YES | | NULL | |
... and other user related columns
mysql> desc UserRole; + -------- + --------- + ------ + ----- + --------- + ------- + | Field | Type | Null | Key | Default | Extra | + -------- + --------- + ------ + ----- + --------- + ------- + | userId | int (11) | NO | PRI | 0 | | | roleId | int (11) | NO | PRI | 0 | | + -------- + --------- + ------ + ----- + --------- + ------- +
0
source to share