Revision
Comparisons with NULL
5. IS NULL or = NULL?
Functions with NULL
COALESCE to the rescue
NULLIF
Revision and practice

Instruction

Nice. Let's explain the behavior of NULL in detail. It's very important to understand it well as it is the source of frequent mistakes when writing SQL queries.

Let's talk about NULL and equality. The condition:

price = 5.99

is not met when the value for price is NULL. Well, that's quite obvious, NULL doesn't equal 5.99 after all.

What's more, NULL never satisfies the equality condition.

But it may seem less obvious that the condition

price = NULL

is NEVER true, even if the price is a NULL indeed. Keep in mind that you need to use IS NULL or IS NOT NULL instead of the equality sign.

Exercise

See for yourself that the equality sign will not work. In our table, there is a row with a NULL launch_date. You can check that by clicking the Database icon on the right. Now, run the query we've prepared and try to find the row.

Console

Code editor

Result

TableConsole