Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How do I select rows where a column has no value in SQLite?

Quick answer

In SQLite, test a column for a missing value with IS NULL: SELECT id, notes FROM tasks WHERE notes IS NULL;. Do not use notes = NULL: an ordinary comparison with NULL evaluates to NULL, and a WHERE clause excludes rows when its expression is NULL. In the example below, only the row whose notes value is NULL is returned; ordinary text values are not.

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I have a SQLite table and want only rows where a column has no value. What should the condition look like? I tried notes = NULL, but it returns no rows.

Geez

Use IS NULL for this test:

SELECT id, notes
FROM tasks
WHERE notes IS NULL;

In SQLite, = NULL does not work as a test for a missing value. An ordinary comparison with a NULL operand evaluates to NULL; in a WHERE clause, rows whose condition is false or NULL are excluded. SQLite treats IS NULL specially, so it selects rows whose column value is NULL. [S1]

For example, suppose tasks contains these invented rows:

id | notes
1  | NULL
2  | call
3  | email

The query returns:

id | notes
1  | NULL

The text values call and email do not match IS NULL. This example describes SQLite behavior; it does not establish whether another database engine uses identical syntax or behavior.

Follow-up question

Can you show the exact difference between the two conditions on that same example, including what happens to the row with NULL?

Geez

With the three example rows, compare these conditions:

SELECT id, notes FROM tasks WHERE notes = NULL;
SELECT id, notes FROM tasks WHERE notes IS NULL;

The first query returns no rows: for the row with notes set to NULL, notes = NULL evaluates to NULL, not true, and the WHERE clause excludes it. For the call and email rows, the comparison also has a NULL operand, so it does not select those rows either. The second query returns only id 1, whose notes value is NULL. [S1]

Replace notes with the name of the column you want to check. Use NULL without quotes: 'NULL' is text, not the SQL null value.

Follow-up question

What if the cell looks blank? How can I tell whether it is actually NULL or an empty string?

Geez

A blank-looking display alone does not tell you whether the stored value is NULL or an empty string. If you want to find either kind of value, use both conditions:

SELECT id, notes
FROM tasks
WHERE notes IS NULL OR notes = '';

That query asks for either a NULL value or an empty string. If you only want SQL NULL values, use WHERE notes IS NULL instead. For illustration, suppose the table also has an empty-string value:

id | notes        | Matches IS NULL? | Matches = ''?
1  | NULL         | Yes              | No
2  | call         | No               | No
3  | email        | No               | No
4  | empty string | No               | Yes

Here, empty string labels the example value; it is not the literal text stored in the cell.

Follow-up question

How should I adapt the query when I need other columns too, and what should I check if I still get no rows?

Geez

List the columns you want after SELECT, keep the table after FROM, and put the null test in WHERE. For example:

SELECT id, task_name, notes
FROM tasks
WHERE notes IS NULL;

If the result is empty, check that you are using the intended table and column. If values that look blank are actually empty strings, IS NULL will not select them; inspect the values without the filter and choose the condition that matches your goal. SQLite’s null comparison rule explains why = NULL is not the fix, but it does not tell you what values your table contains. [S1]

Reusable pattern:

SELECT columns_you_want
FROM table_name
WHERE column_name IS NULL;

Replace the example identifiers with names from your database.

A practical checklist

  • Write the condition as column_name IS NULL to select SQL NULL values.

  • Use the actual table and column names in the query.

  • Do not use column_name = NULL as a missing-value test.

  • Check whether a blank-looking value is NULL or an empty string before choosing a filter.

  • Inspect values without a filter if you need to check what the column contains.

A few more useful answers

Does `IS NULL` also select an empty string?

No. An empty string is a stored text value, not SQL NULL. If you want both, test for column_name IS NULL OR column_name = ''.

Can I use `IS NULL` with a different column?

Yes. Replace the column name in WHERE with the column you want to check, for example WHERE completed_at IS NULL.

Does this guide establish the syntax for every SQL database?

No. The explanation and examples here describe SQLite. Check the documentation for your database engine before assuming its syntax or behavior is the same.

Sources

References used for this guide.

  1. [S1] SQLite SQL Language Expressions — NULL-aware operators
    sqlite.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work