not in vs in

  • I was looking at a T-SQL report query and saw that not in was being used..  I know its better to use IN than NOT IN..

    Any inputs?

  • What context was NOT IN being used, with a list of values or with a subquery?  Depending on the code you are looking at, maybe the NOT IN could be refactored, but it's difficult to tell without seeing it.

  • list of values..

    say 500 databases and each db has a table called queue with 1 million records . out of 500 databases only 300 are active.

  • How about posting the query? Pin the tail on the donkey isn't that much fun.

  • Execution plans, run times, I/O, data, data, data. You can't simply say IN good, NOT IN bad without data. You also can't say NOT IN good, IN bad without data. With the only exception (in my mind) being multi-statement table-valued user-defined functions being the work of the devil, there's not a single construct within SQL Server that is inherently good or bad depending on it's use.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply