It filters rows to include only those where a column's value matches any value in a specified list.
Click to reveal answer
beginner
Write a simple example of a WHERE ... IN clause.
SELECT * FROM employees WHERE department IN ('Sales', 'Marketing'); This returns employees in either Sales or Marketing departments.
Click to reveal answer
intermediate
Can the IN list contain numbers and strings together?
No, the list should contain values of the same data type as the column being filtered.
Click to reveal answer
beginner
How is WHERE ... IN different from multiple OR conditions?
WHERE column IN (a, b, c) is a shorter, clearer way to write WHERE column = a OR column = b OR column = c.
Click to reveal answer
intermediate
What happens if the IN list is empty?
The query returns no rows because no value can match an empty list.
Click to reveal answer
What does this SQL do? SELECT * FROM products WHERE category IN ('Books', 'Toys');
ASelects all products except Books and Toys
BSelects products not in Books or Toys categories
CSelects products with category NULL
DSelects products only in Books or Toys categories
✗ Incorrect
The IN clause filters rows to those where category is either 'Books' or 'Toys'.
Which is equivalent to WHERE id IN (1, 2, 3)?
AWHERE id = 1 AND id = 2 AND id = 3
BWHERE id NOT IN (1, 2, 3)
CWHERE id = 1 OR id = 2 OR id = 3
DWHERE id > 1 AND id < 3
✗ Incorrect
IN with multiple values is like OR conditions for equality.
What data type should the values in the IN list match?
AThe same data type as the column
BAny data type
COnly strings
DOnly numbers
✗ Incorrect
Values in the IN list must match the column's data type for correct filtering.
What result do you get if the IN list is empty?
ANo rows returned
BAll rows returned
CError in SQL syntax
DReturns NULL values only
✗ Incorrect
An empty IN list matches no values, so no rows are returned.
Which is a benefit of using WHERE ... IN over multiple OR conditions?
AIt runs slower
BIt is easier to read and write
CIt only works with numbers
DIt returns more rows
✗ Incorrect
IN makes queries shorter and clearer compared to many OR conditions.
Explain how the WHERE ... IN clause works in SQL and give a simple example.
Think about choosing items from a list.
You got /3 concepts.
Describe the difference between using WHERE ... IN and multiple OR conditions.
Consider how you write the conditions.
You got /3 concepts.
Practice
(1/5)
1. What does the SQL clause WHERE column_name IN (value1, value2, value3) do?
easy
A. It selects rows where column_name matches any value in the list.
B. It updates rows with values in the list.
C. It deletes rows not matching the list.
D. It creates a new table with listed values.
Solution
Step 1: Understand the IN clause purpose
The IN clause checks if a column's value matches any value inside the parentheses list.
Step 2: Identify the effect on row selection
Rows with the column value equal to any listed value are selected; others are ignored.
Final Answer:
It selects rows where column_name matches any value in the list. -> Option A
Quick Check:
WHERE with IN filters rows by listed values [OK]
Hint: IN checks if value matches any in the list [OK]
Common Mistakes:
Thinking IN updates or deletes rows
Confusing IN with creating tables
Assuming IN matches all values at once
2. Which of the following is the correct syntax to select rows where status is either 'active', 'pending', or 'closed'?
easy
A. SELECT * FROM orders WHERE status = IN ('active', 'pending', 'closed');
B. SELECT * FROM orders WHERE status IN ('active', 'pending', 'closed');
C. SELECT * FROM orders WHERE status IN 'active', 'pending', 'closed';
D. SELECT * FROM orders WHERE status IN ('active' 'pending' 'closed');
Solution
Step 1: Check correct use of IN syntax
The correct syntax is column_name IN (value1, value2, ...) without an equals sign.
Step 2: Identify correct punctuation and parentheses
Values must be inside parentheses and separated by commas.
Final Answer:
SELECT * FROM orders WHERE status IN ('active', 'pending', 'closed'); -> Option B
Quick Check:
IN syntax = column IN (values) [OK]
Hint: No '=' before IN; use commas inside parentheses [OK]
Common Mistakes:
Using '=' before IN
Missing commas between values
Omitting parentheses around values
3. Given the table employees with column department, what rows will this query return?
SELECT * FROM employees WHERE department IN ('HR', 'Sales');
medium
A. Rows where department is 'HR' or 'Sales'.
B. Rows where department is 'HR' only.
C. Rows where department is not 'HR' or 'Sales'.
D. All rows regardless of department.
Solution
Step 1: Understand the IN filter on department
The query filters rows where department matches any value in ('HR', 'Sales').
Step 2: Determine which rows match
Only rows with department 'HR' or 'Sales' are returned; others are excluded.
Final Answer:
Rows where department is 'HR' or 'Sales'. -> Option A
Quick Check:
IN filters rows matching listed values [OK]
Hint: IN returns rows matching any listed value [OK]
Common Mistakes:
Thinking it returns rows not in the list
Assuming it returns only one value
Confusing IN with NOT IN
4. Identify the error in this SQL query:
SELECT * FROM products WHERE category IN 'Electronics', 'Toys', 'Books';
medium
A. Incorrect table name.
B. Using IN instead of = operator.
C. Missing parentheses around the list of values.
D. Missing commas between values.
Solution
Step 1: Check syntax of IN clause
The list of values after IN must be enclosed in parentheses.
Step 2: Identify missing parentheses
The query has values listed without parentheses, causing syntax error.
Final Answer:
Missing parentheses around the list of values. -> Option C
Quick Check:
IN requires parentheses around values [OK]
Hint: Always put parentheses around IN value list [OK]
Common Mistakes:
Omitting parentheses around values
Using IN with equals sign
Forgetting commas between values
5. You want to select customers from the orders table whose country is either 'USA', 'Canada', or 'Mexico', but exclude those with status 'cancelled'. Which query correctly uses WHERE with IN and excludes cancelled orders?
hard
A. SELECT * FROM orders WHERE country IN 'USA', 'Canada', 'Mexico' AND status != 'cancelled';
B. SELECT * FROM orders WHERE country IN ('USA', 'Canada', 'Mexico') OR status != 'cancelled';
C. SELECT * FROM orders WHERE country = IN ('USA', 'Canada', 'Mexico') AND status != 'cancelled';
D. SELECT * FROM orders WHERE country IN ('USA', 'Canada', 'Mexico') AND status != 'cancelled';
Solution
Step 1: Use IN correctly for country filter
The country column must be checked with IN ('USA', 'Canada', 'Mexico') without equals sign.
Step 2: Exclude cancelled orders with AND condition
Use AND status != 'cancelled' to exclude those rows.
Final Answer:
SELECT * FROM orders WHERE country IN ('USA', 'Canada', 'Mexico') AND status != 'cancelled'; -> Option D
Quick Check:
IN filters list, AND excludes cancelled [OK]
Hint: Use AND to combine IN filter and exclusion [OK]
Common Mistakes:
Using OR instead of AND causing wrong results
Adding '=' before IN
Omitting parentheses around IN values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.