How to Find Missing Values in SQLite with IS NULL
To find contacts without a phone number, it seems natural to write phone = NULL, but that finds nothing. Missing values need IS NULL. This guide finds the contacts with and without a phone, with real output from SQLite 3.54.1.
Syntax
SELECT <columns> FROM <table> WHERE <column> IS NULL;
SELECT <columns> FROM <table> WHERE <column> IS NOT NULL;
| Part | What it means |
|---|---|
<column> IS NULL | True for the rows where the column has no value |
<column> IS NOT NULL | True for the rows where the column has a value |
SQLite's documentation on IS and IS NOT: "The IS and IS NOT operators work like = and != except when one or both of the operands are NULL."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as is_null.sql:
CREATE TABLE contacts (
name TEXT NOT NULL,
phone TEXT
);
INSERT INTO contacts (name, phone) VALUES ('Ana', '555-0101');
INSERT INTO contacts (name, phone) VALUES ('Ben', NULL);
INSERT INTO contacts (name, phone) VALUES ('Cleo', '555-0103');
SELECT name, phone FROM contacts WHERE phone IS NULL;
SELECT name, phone FROM contacts WHERE phone IS NOT NULL;

- Ben has no phone. Ana and Cleo do.
WHERE phone IS NULLkeeps the rows with no phone.WHERE phone IS NOT NULLkeeps the rows that have one.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table contacts.db ".read is_null.sql"
sqlite3 opens the database file contacts.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+------+-------+
| name | phone |
+------+-------+
| Ben | |
+------+-------+
+------+----------+
| name | phone |
+------+----------+
| Ana | 555-0101 |
| Cleo | 555-0103 |
+------+----------+

IS NULL found Ben, and IS NOT NULL found Ana and Cleo. Every contact landed in exactly one of the two results.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
WHERE phone = NULL | No rows, not even Ben: = with a NULL gives NULL, which is never true | WHERE phone IS NULL |
WHERE phone != '555-0101' to find everyone but Ana | Only Cleo came back: Ben's missing phone isn't "not equal" either | WHERE phone IS NOT '555-0101' returned Ben and Cleo |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A WHERE with = NULL returns nothing | = never matches a missing value | Use IS NULL |
Parse error near line 1 of is_null.sql: table contacts already exists | The script already ran on contacts.db | Delete contacts.db and run the script again |
FAQ
Why doesn't = NULL work?
NULL means "no value", so SQLite can't say whether it equals anything: 'x' = NULL and even NULL = NULL both gave NULL. A WHERE keeps only the rows where its condition is true. IS always gives 1 or 0. The documentation: "It is not possible for an IS or IS NOT expression to evaluate to NULL."
Can I see the result of IS NULL for every row?
Yes, as a column: SELECT name, phone IS NULL FROM contacts; returned 0 for Ana, 1 for Ben and 0 for Cleo. 1 means true.
Conclusion
WHERE phone IS NULL found Ben, the one contact without a phone, and IS NOT NULL found the two with one, where = NULL would have found nobody.
Additional Resources
- IS and IS NOT — how they treat
NULL. - NULL Handling in SQLite Versus Other Database Engines — how SQLite's handling of
NULLcompares with other databases.
