一个查询优化的问题

redshiliu redshiliu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在有3各表或者视图 a,b,c,d都有一个字段code,现要查找a中code同时在b,c,d中的记录
是用多个in子查询号还是先讲b,c,d inner join了好?如下:

方案1:
select code from a where
code in (select code from b) and
code in (select code from c) and
code in (select code from d)

方案2:
select code from a where code in (
select b.code from b,c,d where b.code=c.code and b.code=d.code)

方案3:
select code from a where code in (
select t1.code from (select b.code from b) t1
inner join (select c.code from c) t2 on t1.code=t2.code
inner join (select d.code from d) t3 on t1.code=t3.code
)

请教下三个方案的优缺点及执行流程。

...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
redshiliu
疑难问题 22,298 成员 121,727 内容