typestar

NULL is not a value in SQL

NULL means unknown, so it needs IS rather than an equals sign.

SELECT
    id,
    COALESCE(nickname, name) AS display_name
FROM users
WHERE deleted_at IS NULL
  AND verified_at IS NOT NULL;

How it works

  1. = NULL is never true; use IS NULL and IS NOT NULL.
  2. Any arithmetic touching NULL produces NULL.
  3. COALESCE substitutes a fallback for a missing value.

Keywords and builtins used here

The run, in numbers

Lines
6
Characters to type
116
Tokens
23
Three-star pace
75 tpm

At the three-star pace of 75 tokens a minute, this run takes about 18 seconds.

Type this snippet

Step 4 of 5 in Filtering, step 12 of 23 in Language basics.

← Previous Next →