Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Comparisons with NULL
Functions with NULL
COALESCE to the rescue
Revision and practice
23. Summary


Very nice. It's time to review what we've learned about NULLs so far:

  • Rule number one: never trust a NULL. Keep your eyes open.
  • Use the operator IS NULL to check if the column is NULL.
  • Use the operator IS NOT NULL to check if the column is not NULL.
  • The equality and non-equality conditions (price = 7, price = NULL, price > 15) are never true when the argument is NULL.
  • Arithmetical operations (e.g. a + b) and most functions (e.g. a || b, length(a)) will return a NULL if any of the values is a NULL.
  • COALESCE(x,y,…) returns the first non-NULL argument.
  • NULLIF(x,y) returns x when x != y or NULL when
    x = y.
  • In some databases, you can use NULLS FIRST or NULLS LAST to specify how NULLs are treated in the ORDER BY clause.

Are you ready for a short quiz?


Press Next exercise to get some practice!