Reputation: 121
I know that you should not use the clause NOT IN
when you have NULL
values you're trying to compare to. Also, an arithmetic operation involving a NULL
returns NULL
.
However in other situations NULL
values don't cause issues, for instance, there is no problem with operations such as MAX
, MIN
…
So, what are situations/operations where one should be aware of NULL
values?
Thank you!
Upvotes: 0
Views: 75
Reputation: 15941
Most operations or comparisons involving NULL result in NULL (which is a not "true" value in a boolean sense, but doesn't equal false either).
The most notable exceptions are:
IFNULL()
, COALESCE()
, x IS NULL
, x <=> y
, etc...Upvotes: 0
Reputation: 1269563
You should always pay attention to NULL
values. They are valid values for all SQL types (or almost all, maybe there are a handful of exceptions somewhere). They can also be produced in the course of normal query operations (via outer joins, for instance).
What do they effect? A close approximation is that all functions and operators are affected by NULL
values; most return NULL
if any values are NULL
. There ARE exceptions of course.
In addition, NULL
values cause JOIN
s to fail, unless special care is taken.
Unless you rigorously define all columns as NOT NULL
and avoid outer joins, you should always be thinking about how NULL
values would affect the logic.
Upvotes: 2