AND, OR and parentheses in SQL
Combining conditions: parentheses make the precedence explicit.
SELECT
id,
title,
status
FROM tickets
WHERE status = 'open'
AND (priority = 'high' OR assignee IS NULL)
AND NOT archived;
How it works
ANDbinds tighter thanOR, so groupORbranches yourself.- One condition per line keeps a long filter readable.
NOTinverts the condition that follows it.
Keywords and builtins used here
ANDFROMISNOTNULLORSELECTWHERE
The run, in numbers
- Lines
- 8
- Characters to type
- 121
- Tokens
- 26
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 21 seconds.
Step 1 of 5 in Filtering, step 9 of 23 in Language basics.