typestar

IN and BETWEEN in SQL

Set membership and inclusive ranges, without a pile of OR clauses.

SELECT
    id,
    amount,
    currency
FROM payments
WHERE currency IN ('USD', 'EUR', 'GBP')
  AND amount BETWEEN 10 AND 500
  AND method NOT IN ('cash');

How it works

  1. IN matches any value in the list.
  2. BETWEEN is inclusive on both ends.
  3. NOT IN excludes a list — watch out for NULLs in it.

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
139
Tokens
32
Three-star pace
75 tpm

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

Type this snippet

Step 2 of 5 in Filtering, step 10 of 23 in Language basics.

← Previous Next →