NULL is not an empty string or 0; it is unknown or undefined. NULL is not equal to anything, including itself.
To work with NULL values, use the following built-in functions:
- NULLIF compares two expressions and returns NULL if they are equal. If they are not equal, it returns the first expression.
- SELECT NULLIF(1, 1); returns NULL.
- SELECT NULLIF(1, 2); returns 1.
- IFNULL returns the specified value if the expression is NULL.
- SELECT IFNULL(NULL, 'testing'); returns testing.
- SELECT IFNULL(NULL, NULL); returns NULL.
- ISNULL returns 0 or 1 depending on whether the value is NULL.
- SELECT ISNULL(NULL); returns 1.
- SELECT ISNULL('testing'); returns 0.