Lesson 3: Filtering Data with WHERE
What is the WHERE Clause?
The WHERE
clause filters records based on specific conditions. Without it, SQL queries return all rows in a table.
SQL
SELECT * FROM customers
WHERE city = 'New York';
Comparison Operators
=
→ Equal<>
or!=
→ Not equal>
,<
,>=
,<=
→ Greater/less than
SQL
SELECT first_name, age FROM customers
WHERE age >= 30;
Logical Operators
AND
→ Combines multiple conditions (both must be true)OR
→ At least one condition must be trueNOT
→ Negates a condition
SQL
SELECT first_name, city FROM customers
WHERE city = 'New York' OR city = 'Los Angeles';
Special Operators
IN
→ Match against a list of valuesBETWEEN
→ Match within a rangeLIKE
→ Match using patternsIS NULL
→ Find null values
Practice Quiz
Test your understanding of the WHERE clause: