简化 MySQL 子查询

Simplify MySQL subquery

如何简化此 MySQL 子查询?

Select * From tbl_sys_usuarios Where usr_CvePA IN 
(Select sub_usrCveDep From tbl_sys_usuarios_subalternos Where sub_usrCvePA IN (Select sub_usrCveDep From tbl_sys_usuarios_subalternos Where sub_usrCvePA='237'))

这就是答案!我觉得...

Select * From tbl_sys_usuarios u
Join tbl_sys_usuarios_subalternos sub1 ON u.usr_CvePA=sub1.sub_UsrCveDep
Join tbl_sys_usuarios_subalternos sub2 ON sub1.sub_UsrCvePA=sub2.sub_UsrCveDep and sub2.sub_UsrCvePA='237'

谢谢!

如果您试图摆脱嵌套查询,这应该可行:

SELECT tsu.*
FROM tbl_sys_usarios tsu
INNER JOIN tbl_sys_usarios_subalternos tsus_a ON tsu.usr_CvePA = tsus.sub_usrCveDep
INNER JOIN tbl_sys.tbl_sys_usarios_subalternos tsus_b ON tsus_a.sub_usrCvePA = tsus_b.sub_usrCveDep
WHERE tsus_b.sub_usrCvePA = '237'