typestar

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

  1. AND binds tighter than OR, so group OR branches yourself.
  2. One condition per line keeps a long filter readable.
  3. NOT inverts the condition that follows it.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 5 in Filtering, step 9 of 23 in Language basics.

← Previous Next →