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
= NULLis never true; useIS NULLandIS NOT NULL.- Any arithmetic touching NULL produces NULL.
COALESCEsubstitutes a fallback for a missing value.
Keywords and builtins used here
ANDASCOALESCEFROMISNOTNULLSELECTWHERE
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.
Step 4 of 5 in Filtering, step 12 of 23 in Language basics.