SQL not in or left join

There is an interesting article here: http://blog.sqlauthority.com/2008/04/22/sql-server-better-performance-left-join-or-not-in/

It’s interesting to note that when I tried to recreate this in the real world, the not-in was not returning anything.  This can happen if the sub-query can return nulls.  So, if the FK allows nulls, one must change the sub-query to something like

SELECT ProductID
FROM Production.WorkOrder
WHERE
ProductID IS NOT NULL

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s