SQL NULL value
NULL values represent missing unknown data.
By default, table columns can store NULL values.
This chapter explains the IS NULL and IS NOT NULL operators.
SQL NULL value
If a column in the table is optional, then we can insert a new record or update an existing record without adding a value to the column record of. This means that the field will be saved with a NULL value.
NULL values are handled differently than other values.
NULL is used as a placeholder for unknown or inapplicable values.
Comments: NULL and 0 cannot be compared; they are not equivalent.
SQL NULL value processing
Please see the "Persons" table below:
LastName | FirstName | Address | City | |
---|---|---|---|---|
Hansen | Ola | |||
Svendson | Tove | Borgvn 23 | Sandnes | |
Pettersen | Kari |
SQL IS NULLHow do we select only records with NULL values in the "Address" column? We must use the IS NULL operator:
FirstName | Address | |
---|---|---|
Ola | ||
Kari |
LastName | FirstName | Address |
---|---|---|
Svendson | Tove | Borgvn 23 |
In the next section, we learn about ISNULL(), NVL(), IFNULL() and COALESCE() function.