IN vs. JOIN with large rowsets

前端 未结 12 1734
天命终不由人
天命终不由人 2020-11-30 20:45

I\'m wanting to select rows in a table where the primary key is in another table. I\'m not sure if I should use a JOIN or the IN operator in SQL Server 2005. Is there any si

12条回答
  •  情深已故
    2020-11-30 21:17

    Speaking from experience on a Table with 49,000,000 rows I would recommend LEFT OUTER JOIN. Using IN, or EXISTS Took 5 minutes to complete where the LEFT OUTER JOIN finishes in 1 second.

    SELECT a.*
    FROM a LEFT OUTER JOIN b ON a.c = b.d
    WHERE b.d is not null -- Given b.d is a primary Key with index
    

    Actually in my query I do this across 9 tables.

提交回复
热议问题