Easy Filtering rows Employees database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

namesalary
Mei Chen7600
Hana Kim7300

Rows can come in any order. Column names do not have to match.

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).

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.