Convert SQL WHERE IN to JOIN

后端 未结 2 1888
再見小時候
再見小時候 2020-12-22 09:57

I have a database storing various information about fictional people. There is a table person with general information, such as name, adress etc and some more specific table

2条回答
  •  被撕碎了的回忆
    2020-12-22 10:38

    Depends on your SQL engine. Newer SQL systems that have reasonable query optimizers will most likely rewrite both IN and JOIN queries to the same plan. Typically, a sub-query (IN Clause) is rewritten using a join.

    In simple SQL engines that may not have great query optimizers, the join should be faster because they may run sub-queries into a temporary in-memory table before running the outer query.

    In some SQL engines that have limited memory footprint, however, the sub-query may be faster because it doesn't require joining -- which produces more data.

提交回复
热议问题