Negating a condition in SQL
NOT reads well until NULLs arrive, and then it quietly drops rows.
SELECT
id,
status,
total
FROM orders
WHERE status NOT IN ('canceled', 'refunded')
AND status <> 'draft'
AND shipped_at IS NOT NULL;
How it works
NOT INandNOT LIKEnegate the whole predicate.<>is the portable not-equal;!=works in most engines too.NOT INwith a NULL in the list matches nothing at all.
Keywords and builtins used here
ANDFROMINISNOTNULLSELECTWHERE
The run, in numbers
- Lines
- 8
- Characters to type
- 131
- Tokens
- 28
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 22 seconds.
Step 5 of 5 in Filtering, step 13 of 23 in Language basics.