Sqlite Is Null Condition

SQLite: IS NULL Condition

This SQLite post explains how to use the SQLite IS NULL condition with syntax and examples.

Description

The SQLite IS NULL Condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the IS NULL Condition in SQLite is:

expression IS NULL

Parameters or Arguments

expression

The expression to test whether it is a NULL value.

Note

  • If expression is a NULL value, the condition evaluates to TRUE.
  • If expression is not a NULL value, the condition evaluates to FALSE.

Example - With SELECT Statement

Let's look at an example of how to use SQLite IS NULL in a SELECT statement:

SELECT *
FROM employees
WHERE department IS NULL;

This SQLite IS NULL example will return all records from the employees table where the department contains a NULL value.

Example - With INSERT Statement

Next, let's look at an example of how to use SQLite IS NULL in an INSERT statement:

INSERT INTO temp
(temp_employee_id, temp_last_name, temp_first_name)
SELECT employee_id, last_name, first_name
FROM employees
WHERE first_name IS NULL;

This SQLite IS NULL example will insert records into the temp table where the first_name contains a NULL value.

Example - With UPDATE Statement

Next, let's look at an example of how to use SQLite IS NULL in an UPDATE statement:

UPDATE employees
SET first_name = 'Unknown'
WHERE first_name IS NULL;

This SQLite IS NULL example will update records in the employees table and set the first_name to 'Unknown' where the first_name field contains a NULL value.

Example - With DELETE Statement

Next, let's look at an example of how to use SQLite IS NULL in a DELETE statement:

DELETE FROM employees
WHERE employee_id IS NULL;

This SQLite IS NULL example will delete all records from the employees table where the employee_id contains a NULL value.