This SQLite post explains how to use the SQLite IS NULL condition with syntax and examples.
The SQLite IS NULL Condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the IS NULL Condition in SQLite is:
expression IS NULL
The expression to test whether it is a NULL value.
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.
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.
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.
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.