sql optimization, how will change as exists in

Original sql statement

- identify all the permissions menu the user has permission table according to 
the SELECT * from tb_power the WHERE in the above mentioned id ( 
 the SELECT power_id from tb_role_power in the WHERE role_id ( 
   the SELECT role_id from tb_user_role the WHERE userid = 1 
 ) 
)

Optimized

1 -- 优化
2 select * from tb_power  p where  exists(
3  select power_id  from  tb_role_power rp where  exists(
4    select 1 from tb_user_role ur where userid=1 and ur.role_id=rp.role_id
5  )  and p.id=rp.power_id
6 )

 

Guess you like

Origin www.cnblogs.com/yanpingping/p/11210699.html