The SQL NULL value means a field with no value present in it.
If a field in a table is optional in other words if it’s not mandatory, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.
Note: “A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!”
There are two options we can use either IS NULL tor can be IS NOT NULL. IS NULL Syntax
IS NULL
IS NOT NULL
SELECT column_1, column_2 FROM table_name WHERE column_1 IS NULL;
IS NOT NULL Syntax
SELECT column_1, column_2 FROM table_name WHERE column_1 IS NOT NULL;
Consider we have a customer table in which one record is having a null value and in another record all data is present.
IS NULL Operator The IS NULL operator is used for checking empty values (NULL values).
SELECT * FROM customers WHERE address IS NULL; -- 1 record found. -- +-----------------------------------------+ -- | customerID | name | address | -- |-----------------------------------------| -- | 90 | White Clover | null | -- +-----------------------------------------+
IS NOT NULL Operator The IS NOT NULL operator is used for checking non-empty values (NOT NULL values).
SELECT * FROM customers WHERE address IS NOT NULL; -- 1 record found. -- +-----------------------------------------------+ -- | customerID | name | address | -- |-----------------------------------------------| -- | 89 | Wilman Kala | Keskuskatu 45 | -- +-----------------------------------------------+