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
INmatches any value in the list.BETWEENis inclusive on both ends.NOT INexcludes a list — watch out for NULLs in it.
Keywords and builtins used here
ANDBETWEENFROMINNOTSELECTWHEREmethod
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.
Step 2 of 5 in Filtering, step 10 of 23 in Language basics.