MySQL SQLLesson 43Free preview
MySQL Null Functions
This lesson is part of MySQL · All levels
Summary
MySQL provides several functions to handle the NULL values, including IFNULL, COALESCE, and NULLIF. IFNULL replaces the NULL value with a substitute value so that the calculation results or display are more neat. COALESCE is more flexible because it accepts many arguments and returns the first value that is not NULL.
Key points
- IFNULL(a, b) returns b when a is NULL, in addition returns a
- COALESCE accepted many arguments and returned the first instead of NULL
- NULLIF(a, b) yields NULL if a is equal to b, useful to prevent zero division
- The value of NULL cannot be compared to = NULL, must use IS NULL
- This function is useful so that the report view does not display the word NULL
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.