Home / SQL / Reference / Filtering

SQL AND, OR, NOT

Combine conditions.

Syntax

WHERE (a AND b) OR NOT c

AND needs both sides true, OR needs at least one, NOT flips. AND is evaluated before OR, so use brackets when you mix them.

Example

Query (on the shop database used in the SQL course)

SELECT name, category, price
FROM products
WHERE (category = 'Electronics' AND price < 100)
   OR category = 'Books';

Result

namecategoryprice
Wireless mouseElectronics29.0
USB-C hubElectronics49.0
Python Crash Course (book)Books45.0
Deep Learning (book)Books89.0
SQL Pocket GuideBooks25.0

5 rows

Related

Learn it step by step in the free lesson WHERE: Filtering Rows, with exercises that check your queries.