Skip to main content
Log inGet a demo
← SQL Dictionary
Logical operators

SQL IS NULL

What is SQL IS NULL?

The SQL IS NULL operator is used to filter rows where a specified column's value is NULL. A NULL value in a database represents the absence of data, and the IS NULL operator is used to identify and select rows that contain NULL values in a particular column.

When you would use it

You would use the SQL IS NULL operator when you need to filter data from a table based on whether a column's value is NULL. This is useful when you want to retrieve records that lack data or records that have not been assigned a value for a specific attribute.

Syntax

The syntax for using the IS NULL operator is as follows:

SELECT columns
FROM table_name
WHERE column_name IS NULL;
  • columns: The columns you want to retrieve in the query.
  • table_name: The name of the table containing the data.
  • column_name: The name of the column you want to filter based on whether it contains NULL values.

Parameter values

  • columns: The columns you want to retrieve in your query.
  • table_name: The name of the table where the data is stored.
  • column_name: The name of the column you want to filter based on whether it contains NULL values.

Example query

Suppose we have a table named "employees" with columns "employee_id," "employee_name," and "supervisor_id." We want to retrieve employees who do not have a supervisor assigned (i.e., the "supervisor_id" is NULL):

SELECT employee_id, employee_name
FROM employees
WHERE supervisor_id IS NULL;

In the above query, we use the IS NULL operator to filter employees who do not have a supervisor assigned.

Example table response

Assuming the "employees" table contains the following data:

| employee_id | employee_name | supervisor_id |
|------------ |-------------- | -------------- |
| 1          | John         | NULL           |
| 2          | Alice        | 1              |
| 3          | Bob          | NULL           |
| 4          | Carol        | 2              |
| 5          | David        | NULL           |

The query mentioned earlier would return the following result:

| employee_id | employee_name |
|------------ |-------------- |
| 1          | John         |
| 3          | Bob          |
| 5          | David        |

This result includes employees without assigned supervisors, as indicated by the NULL values in the "supervisor_id" column.

Use cases

  • Identifying records with missing or unspecified data (NULL values).
  • Retrieving records that lack values for a particular attribute.
  • Ensuring data quality and integrity by identifying incomplete records.

SQL languages this is available for

The SQL IS NULL operator is a standard SQL feature and is available in most relational database management systems (RDBMS) that support SQL. This includes popular RDBMS like MySQL, PostgreSQL, Oracle, SQL Server, and SQLite. The specific syntax and behavior may vary slightly between database systems, but the fundamental functionality remains the same.


Keep reading

SQL BETWEEN

Read article

SQL IS NOT NULL

Read article

SQL AND

Read article

Ready to put your SQL knowledge to work?

Practice writing SQL to call data from the warehouse and sync it into Google Sheets in this 5 minute interactive demo.

Hightouch Audiences user interface.