Combine conditions with AND
Question
Show the name and salary of employees in department 1 (Engineering) who earn less than 8000.
employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city
Your query
Ctrl+Enter to run
Result
Expected result
| name | salary |
|---|---|
| Mei Chen | 7600 |
| Hana Kim | 7300 |
Hint
Both conditions must be true, so join them with AND.
Show the solution
solution.sql
Run this code
SELECT name, salary
FROM employees
WHERE department_id = 1 AND salary < 8000;
Why it works
AND keeps a row only when both conditions are true. Engineering has four people; two of them earn 8000 or more, so two remain.
Common mistake
Mixing AND and OR without brackets is a common trap. AND is evaluated first, so a = 1 OR b = 2 AND c = 3 means a = 1 OR (b = 2 AND c = 3).