AND, OR and NOT

Stage 2: Filtering · Lesson 6 of 17 · 5 min read · free, interactive

Combine conditions with AND (both must be true) and OR (at least one is true). NOT flips a condition.

SELECT name, country, level FROM players WHERE country = 'VN' AND level >= 10;
SELECT name, country FROM players WHERE country = 'JP' OR country = 'US';

AND binds tighter than OR, just like × before + in maths. This query does not mean what it looks like:

SELECT name, country, level FROM players WHERE country = 'VN' OR country = 'JP' AND level >= 8;

It reads as: VN, or (JP and level ≥ 8).

Use parentheses to say what you mean:

SELECT name, country, level FROM players WHERE (country = 'VN' OR country = 'JP') AND level >= 8;

Practice

Each answer runs in your browser and is checked on hidden data.

Previous: Missing values: NULL · Next: Lists and ranges: IN and BETWEEN · All lessons