Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Review
Comparisons with NULL
6. NULL with non-equality
Functions with NULL
COALESCE to the rescue
NULLIF
Review and practice

Instruction

See? The query returned nothing. You must use IS (NOT) NULL to check for NULL and NOT NULL values. If you don't use it, the query will return nothing.

It's easy to remember that x = NULL is wrong, but this phenomenon is much more difficult to notice with non-equality. Take a look at the column production_area. If you want to get all the products which have been produced outside EU, you could write:

SELECT *
FROM product
WHERE production_area != 'EU';

... but this query will not return those rows which have NULL in the column production_area.

Is this correct? It depends. If you want to find all the products which have a set value which is other than 'EU', then the condition is OK. If you want to find all the rows with anything other than 'EU' (including NULLs), then we need to use the following construction:

SELECT *
FROM product
WHERE production_area != 'EU'
  OR production_area IS NULL;

Exercise

Select the name for all the products with a price different than 299.99. Include NULLs!

Stuck? Here's a hint!

In order to include NULLs, you need to write two conditions in the WHERE clause, joined by OR. Use IS NULL in one of them.