correlated query /subquery VS join query

喜欢而已 提交于 2019-12-11 17:53:03

问题


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


回答1:


yes and no...

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

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

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




回答2:


Yes, but it means that what you JOIN to can appear in the result set. A subquery in either an EXISTS or IN clause would not have this risk.



来源:https://stackoverflow.com/questions/2676874/correlated-query-subquery-vs-join-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!