Lesson Description
Combine multiple conditions in a WHERE clause.
Lesson 1 of 4
Progress: 0/3 exercises solved (0%)
Solve all exercises below to unlock the next lesson.
Lesson Description
Combine multiple conditions in a WHERE clause.
Easy Project
Mini project: Turn this lesson into a real-world query artifact by writing one clean business report query and validating output quality.
You can combine multiple conditions in WHERE using AND, OR, and NOT.
SELECT first_name, salary
FROM employees
WHERE department_id = 60 AND salary > 5000;
SELECT first_name, department_id
FROM employees
WHERE department_id = 60 OR department_id = 80;
SELECT first_name, department_id
FROM employees
WHERE NOT department_id = 90;
NOT binds tightest, then AND, then OR. This can cause surprises:
-- WARNING: this means department = 60 AND (salary > 5000 OR department = 80)
WHERE department_id = 60 AND salary > 5000 OR department_id = 80
Use parentheses to make intent explicit:
WHERE (department_id = 60 OR department_id = 80)
AND salary > 5000
AND and OR — it prevents logic bugs and aids readability.NOT can be used with IN, BETWEEN, LIKE, and EXISTS (covered in later lessons).This lesson is part of Filtering & Logic. Focus on the core idea in AND, OR, NOT, then validate with deliberate practice.
What to master
Common mistakes
High-level strategy
Task ladder
Transparent data checks
Retention loop
Logical reasoning for commands
WHERE
Why: Limits rows to only the business-relevant subset.
Memory cue: Filter early to reduce noise.
ORDER BY
Why: Makes output deterministic and reviewable.
Memory cue: No ORDER BY means no guaranteed row order.
AS alias
Why: Makes output columns readable for teams and reports.
Memory cue: If the name is clear, the query is easier to trust.
Concept check
3 quick questions. One at a time. Instant score at the end.
Return first_name, last_name, and salary for employees in IT (department 60) or Sales (department 80) earning more than 6000.
Return first_name, last_name, department_id, and salary for employees who are either in department 90 or earn more than 12000.
From the store sandbox, return first_name, last_name, and country for customers whose country is not 'USA', ordered by country, then last_name.
Lesson 1 of 4
0/3 solved (0%)
Finish this lesson to unlock next.