Can I get better performance using a JOIN or using EXISTS?

前端 未结 12 1837
鱼传尺愫
鱼传尺愫 2020-12-03 13:04

I have two tables Institutions and Results and I want to see if there are any results for institutions that way I can exclude the ones that don\'t have results.

Can

12条回答
  •  借酒劲吻你
    2020-12-03 13:53

    If you're referring to using a left (or right) outer join or a not exists subquery, I'm fairly certain the left outer join wins performance-wise. For example:

    SELECT t1.* FROM table1 t1 LEFT OUTER JOIN table2 t2 ON t1.id = t2.id WHERE t2.id IS NULL

    The above should be quicker than the equivalent sub-query, and if you're referring specifically to exists - well, where structure allows, an inner join will always be the preferred option.

提交回复
热议问题