What is WHERE?
WHERE filters rows based on conditions. Like a search filter - only shows results that match your criteria.
How WHERE Works
Step-by-step:
- SELECT * FROM students - Start with all rows
- WHERE age > 20 - Apply the filter
- Check each row - Is age greater than 20?
- Result - Only matching rows returned
Basic Syntax
SELECT columns FROM table WHERE condition;Comparison Operators
- = Equal:
WHERE age = 20 - != Not equal:
WHERE grade != 'F' - > Greater than:
WHERE age > 20 - < Less than:
WHERE age < 20 - >= Greater or equal:
WHERE age >= 20 - <= Less or equal:
WHERE age <= 20
Combining Conditions
-- AND: Both must be true
SELECT * FROM students WHERE age > 20 AND grade = 'A';
-- OR: Either can be true
SELECT * FROM students WHERE grade = 'A' OR grade = 'B';Special Operators
-- BETWEEN: Range of values
SELECT * FROM students WHERE age BETWEEN 18 AND 25;
-- IN: Match any in list
SELECT * FROM students WHERE grade IN ('A', 'B');
-- LIKE: Pattern matching
SELECT * FROM students WHERE name LIKE 'A%';Try WHERE Below
Use the playground to practice WHERE queries. Try:
SELECT * FROM students WHERE age > 20;SELECT * FROM students WHERE grade = 'A';
What Comes Next
Next: Learn ORDER BY to sort your results.
Try WHERE
Filter data with conditions. Try: SELECT * FROM students WHERE age > 20;
Source Table: students
| id | name | age | grade |
|---|---|---|---|
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
| 3 | Charlie | 21 | A |
| 4 | David | 23 | B |
4 rows
SQL Editor
Loading...