// conditional reference

SQL IS NULL predicate

Tests for NULL directly, returning TRUE or FALSE and never UNKNOWN.

カテゴリ
条件付き
Returns
boolean
In this category
22 of 43

構文

x IS NULL | x IS NOT NULL | (a, b) IS NULL

エンジンサポート

エンジンSupportメモ
SQL Server はい Supported under this name.
PostgreSQL はい Supported under this name.
MySQL はい Supported under this name.
SQLite はい Supported under this name.
Oracle はい Supported under this name.

例

Any engine

SELECT * FROM users WHERE deleted_at IS NULL;

PostgreSQL

SELECT * FROM t WHERE (a, b) IS NULL;

知っておくと便利なこと

  • x = NULL is UNKNOWN even when x is NULL; only IS NULL reports it.
  • For a single value, IS NULL is exactly NOT (x IS NOT NULL), and both are TRUE-or-FALSE, so they compose with NOT cleanly.
  • Row forms break that symmetry in PostgreSQL: (a, b) IS NULL is TRUE only when every field is NULL, and (a, b) IS NOT NULL is TRUE only when every field is non-NULL, so (1, NULL) fails both.
  • WHERE col IS NULL can use a plain B-tree index in PostgreSQL, SQL Server, MySQL and SQLite. Oracle B-tree indexes skip rows whose key columns are all NULL, so a single-column index cannot answer IS NULL; index (col, 0) instead.

Questions about IS NULL

Why does x = NULL fail?

Any comparison with NULL yields UNKNOWN, and WHERE keeps only TRUE; IS NULL is the predicate built for it.

How is IS NULL different from ISNULL()?

IS NULL tests; ISNULL (SQL Server), IFNULL and NVL substitute a value for NULL.

What does (a, b) IS NULL check?

In PostgreSQL, that all fields are NULL. (a, b) IS NOT NULL checks that all fields are non-NULL, so the two are not complements: a half-NULL row fails both.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.