Home › Learn › SQL › Reading rows

AND, OR, NOT

Lesson 4 of 26. Combine conditions.

AND requires both conditions, OR either one, NOT flips one. AND binds tighter than OR, so a OR b AND c means a OR (b AND c); use parentheses whenever both appear in one clause, for your reader as much as for the database.

Think of the condition as a question asked of each row: "is this hardware costing under 100, or is it stationery?" Rows answering yes are kept.

SELECT name FROM employees WHERE dept = 'Engineering' AND salary > 7000;

Your task

Show the name, category, and price of products that are either hardware costing less than 100, or anything in the stationery category.

Hint 1

(category = 'hardware' AND price < 100) OR category = 'stationery'

Show the solution
SELECT name, category, price FROM products
WHERE (category = 'hardware' AND price < 100) OR category = 'stationery';

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.