SQLite NULL Values
What is a NULL Value?
A field with a NULL value is a field with no value.
For example, if you insert a record without a value for a column, that column gets the value NULL.
Note: NULL is not the same as zero, or as an empty text. NULL means that there is no value at all.
How to Test for NULL Values
You cannot test for NULL with operators like = or <>. Use IS NULL and IS NOT NULL instead:
IS NULL syntax:
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
IS NOT NULL syntax:
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
The IS NULL Operator
There are no NULL values in the Customers table, so this example first adds a customer without an address. Then it selects the customers that have no address:
Example
INSERT INTO Customers (CustomerName, Country)
VALUES ('Cardinal', 'Norway');
SELECT CustomerName, Address
FROM Customers
WHERE Address IS NULL;
Try it Yourself »
Tip: Always use IS NULL to look for NULL values.
The IS NOT NULL Operator
IS NOT NULL selects the records that have a value. This example selects the customers that have an address:
Example
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;
Try it Yourself »
Why = NULL Does Not Work
A comparison with NULL never gives true or false. It gives NULL, because the value is unknown:
That is why WHERE Address = NULL never finds any records.