mysql子查询相关问题



-- 可行 子查询可用到多层
explain select * from BD_ORG org
LEFT JOIN
BD_CONTRACT_BUSINESSMAN B on B.S_CONTRACT_ID =
(select 1 from EF_ARAP where BILL_ID = (select org_id from BD_ORG where org_id=(select org_id from BD_COMPANY where company_id=org.ORG_ID)) )
;

-- 报错 子查询只能关联外部条件到最外面一层
explain  select * from BD_ORG org
LEFT JOIN (
SELECT * FROM
BD_CONTRACT_BUSINESSMAN B WHERE B.S_CONTRACT_ID =
(select 1 from EF_ARAP where BILL_ID = (select org_id from BD_ORG where org_id=org.ORG_ID) )
)S ON 1=1;

注:表无具体含义,只为验证外层条件是否可用.



你可能感兴趣的:(mysql子查询相关问题)