iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

SQL WHERE

WHERE filters rows. Only rows where the condition evaluates to TRUE appear in the result.

Comparison operators

OperatorMeans
=Equal
<> or !=Not equal
<, >, <=, >=Magnitude
BETWEEN a AND bIn a range, inclusive
IN (x, y, z)In a list
LIKE 'A%'Pattern match
IS NULL / IS NOT NULLNull check

Combining conditions

SQL
SELECT *
FROM products
WHERE price > 50
  AND stock > 0
  AND (category = 'books' OR category = 'music');

Quotes matter

  • String values are wrapped in single quotes: 'AU'.
  • Numbers and booleans are unquoted: 42, true.
  • Identifiers (table/column names) use backticks in MySQL or double quotes in PostgreSQL/standard SQL.
Tip: Never compare to NULL with = — it never returns true. Always use IS NULL / IS NOT NULL.

Example

Example
SELECT * FROM products
WHERE price > 100;
Try it Yourself »

Exercise

Filter for products that cost more than 50.

SELECT * FROM products price > 50;

Test yourself

Q1. WHERE filters…
Q2. To compare to NULL you use…
Q3. Which is the "not equal" operator (besides !=)?

Discussion

Loading…