SELECT with IN Operator
Return employees in departments 10, 20, or 30.
- Filtering
Exercise brief
Understand the request
Workforce planner A cross-functional review only covers IT, HR, and Finance.
Show first_name, last_name, and department_id for employees who belong to IT (10), HR (20), or Finance (30). Use the IN operator instead of three separate OR conditions.
Return
- Return first_name, last_name, and department_id.
Constraints
- Use the IN operator in the filter.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameVARCHAR(50)last_nameVARCHAR(50)department_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
IN takes a parenthesised list of values. The row passes if the column equals any one of them.
Hint 2
WHERE department_id IN (10, 20, 30) is equivalent to WHERE department_id = 10 OR department_id = 20 OR department_id = 30.
Hint 3
Project the two name fields and department_id, then filter department_id with a three-value IN list.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT first_name, last_name, department_id FROM employees WHERE department_id IN (10, 20, 30);Why this works
IN is syntactic sugar over a chain of equality ORs. It is cleaner, less bug-prone, and easier for the optimiser. Use NOT IN for the inverse — but be careful: NOT IN with a list that contains NULL returns no rows because of three-valued logic.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | department_id |
|---|---|---|
| John | Smith | 10 |
| Alice | Johnson | 10 |
| Bob | Wilson | 10 |
| Carol | Davis | 20 |
| David | Brown | 30 |
| Grace | White | 10 |
| Henry | Clark | 20 |
| Ivy | Martinez | 30 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Open the interactive workspace and practice across SQL topics.