They are semantically identical.
IN
is simply a shorthand for equality operators, as in your second example. Performance should also be identical.
The type should not matter; it will always evaluate the string of equalities.
There is a difference when you use NOT IN
and data that may be NULL
, although - NULL
will not evaluate to false to compare NOT IN
, so you can get strings that you did not expect in the result set.
As an example:
SELECT 'Passed!' WHERE NULL NOT IN ('foo', 'bar')
The above query will not return a string, although at a nominal value of NULL
there is neither 'foo'
or 'bar'
- this is because NULL
is an unknown state, and SQL cannot say with certainty that an unknown value is NOT one of the IN
values.
Jnk
source share