SELECTDISTINCT p.* FROM t_permission p LEFTJOIN t_role_permission trp ON trp.`permissionid`=p.`id` LEFTJOIN t_role tr ON tr.`id`=trp.`roleid` WHERE tr.id IN( SELECT t_r.id FROM t_role t_r LEFTJOIN t_user_role t_u_r ON t_u_r.`roleid`=t_r.`id` WHERE t_u_r.`userid`=31 );
子查询不太推荐,比较影响性能 推荐连接查询 SELECTDISTINCT p.* FROM t_permission p LEFTJOIN t_role_permission trp ON trp.`permissionid`=p.`id` LEFTJOIN t_role tr ON tr.`id`=trp.`roleid` LEFTJOIN t_user_role tur ON tur.`roleid`=tr.`id` LEFTJOIN t_user tu ON tu.`id`=tur.`userid` WHERE tu.`id`=31;