IN()
results
The table below shows all the possible results for IN
and NOT IN
.To use it properly, start with the first question in the left column.If the answer is No, move on to the next line.As soon as an answer is Yes, read the results from the second and third columns and you’re done.
Conditions |
Results |
|
---|---|---|
|
|
|
Is the list empty? |
|
|
Else, is |
|
|
Else, is at least one list element equal to |
|
|
Else, is at least one list element |
|
|
Else (i.e. all list elements are non- |
|
|
In many contexts (e.g. within IF
and WHERE
clauses), a NULL
result behalves like false
in that the condition is not satisfied when the test expression is NULL
.On the one hand this is convenient for cases where you might expect false
but NULL
is returned: you simply won’t notice the difference.On the other hand, this may also lead you to expect true
when the expression is inverted (using NOT
) and this is where you’ll run into trouble.In that sense, the most “dangerous” case in the above table is when you use an expression of the type “A NOT IN (<list>)
”, with A
indeed not present in the list (so you’d expect a clear true
result), but the list happens to contain one or more NULL
s.
Caution
|
Be especially careful if you use
If |
Warning
|
Bug alert
All Firebird versions before 2.0 contain a bug that causes
Please realise that an index may be active even if it has not been created explicitly, namely if a key is defined on Example: Table
should both return
returns a dataset with one record — containing the field with value 3 — while it should have returned an empty set.Other errors may also occur, e.g. if you use “ As an alternative to |