跨数据库left join的问题??

attilax attilax 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
需要跨数据库left join 俩个表a,b。。数据库是不同类型的数据库oracle,mssql

select * from a left join b on a.id=b.id where b.col1="xxx"
和
select * from a left join b on a.id=b.id where a.col1="ccc"

这俩个sql要怎么实现呢???

我的思路是比如:select * from a left join b on a.id=b.id where b.col1="xxx"
先查询 select b.id from b where b.col1="xxx"
然后在 select * from a where a.id in (b.id)

思路看起来可行,但是好像与语句顺序相反。而且如果b.id很多的话,导致 where a.id in (b.id) 会很长,in查询好像也有长度限制,不过可以使用for循环解决,比较麻烦些。。

如果先执行select * from a left join b on a.id=b.id 再根据where语句过滤 ,好像俩面会加载好多无用的记录集。。


有没有更好的思路呢??
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
attilax
Java EE 67,535 成员 225,843 内容