Lesson 2 of 10 · 9 min · 3 hands-on steps

Filtering Rows with WHERE

AND, OR, IN, BETWEEN, LIKE and NULL. Ask exactly the question you mean.

WHERE picks the rows you want

Every example below runs against a practice database. Press Run and experiment.

SQL · try it
SELECT name, city FROM customers WHERE city = 'Lagos';

Text goes in single quotes in SQL.

Combining conditions

SQL · try it
SELECT name, salary FROM employees
WHERE department_id = 1 AND salary > 100000;
SQL · try it
SELECT name FROM customers
WHERE city IN ('Seoul', 'Pune');
SQL · try it
SELECT name, hired FROM employees
WHERE hired BETWEEN '2022-01-01' AND '2023-12-31';

Pattern matching with LIKE

Pattern Matches
'A%' starts with A
'%a' ends with a
'%ar%' contains "ar"
'_o' two letters, second is o (_ = exactly one character)
SQL · try it
SELECT name FROM products WHERE name LIKE '%o%';

NULL means "unknown"

A missing value is NULL. You can't compare it with =. Use IS NULL or IS NOT NULL:

SQL · try it
SELECT 'NULL = NULL is…', NULL = NULL, NULL IS NULL;

That first comparison gives NULL (unknown), not true. It's one of the most famous SQL gotchas.

🧪 Practice: 3 steps

0 / 3 done

Step 1 of 3 · Lagos customers

Tables: customers(id, name, city).

Return the name of every customer in Lagos.

SQL
SELECT * FROM customers;

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. How do you check for a missing value in SQL?

  2. Which is the same as city = 'Lagos' OR city = 'Pune'?

Create a free account to track your progress.