相关查询/子查询VS联接查询 [英] correlated query /subquery VS join query

查看:176
本文介绍了相关查询/子查询VS联接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能否始终将常用的子查询/相关子查询转换为联接类型查询?

can we always convert a usual subquery/correlated subquery to join type query?

推荐答案

是,不是...

  • 是的,因为JOIN/EXISTS/IN通常会给出相同的计划,并且往往是相同的

  • Yes, in that JOIN/EXISTS/IN usually give the same plan and are often the same

否,因为如果EXISTS表的主表具有> 1行,则需要DISTINCT以避免重复

No, in that if the EXISTS table has > 1 row for the main table you'll need DISTINCT to avoid dupes

如果相关,并且我不需要EXISTS表中的数据,我会坚持使用EXISTS类型查询

I'd stick with an EXISTS type query if this is relevant and you don't need data from the EXISTS table

这篇关于相关查询/子查询VS联接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆