What does the IN operator do?
IN is an operator that checks whether a value is in a list of possible options.
It's used inside WHERE, to avoid writing long chains of OR.
How it works
IN compares a column's value against a set of values listed in parentheses.
If the value matches at least one element from the list, the condition is true.
SELECT *
FROM employees
WHERE city IN ('Kyiv', 'Lviv', 'Odesa');The query selects every employee whose city is Kyiv, Lviv, or Odesa.
The alternative without IN
Without it, you'd have to write it out long-form:
WHERE city = 'Kyiv' OR city = 'Lviv' OR city = 'Odesa'IN does the same thing, but shorter and clearer.
Negation
Adding NOT gives you a check for "the value isn't in the list":
WHERE department NOT IN ('HR', 'Finance');This excludes everyone from the HR and Finance departments.
A subquery can be used too
WHERE id IN (SELECT employee_id FROM bonuses);Selects every employee whose ID appears in the bonuses table.
Summary:
IN is a convenient way to filter against a whole set of values at once.
It works with numbers, text, and even the results of subqueries.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.