Recall & Review
beginner
What does the IN operator do in SQL?
The IN operator checks if a value matches any value in a list or subquery. It helps filter rows where a column's value is in a specified set.
Click to reveal answer
beginner
How does the NOT IN operator work?
The NOT IN operator filters rows where a column's value is NOT in the specified list or subquery. It excludes those values.
Click to reveal answer
beginner
Write a simple SQL query using IN to find employees in departments 1, 2, or 3.
SELECT * FROM employees WHERE department_id IN (1, 2, 3);
Click to reveal answer
intermediate
What happens if the list in NOT IN contains NULL?
If the list contains NULL, NOT IN may return no rows because comparisons with NULL are unknown. It's safer to avoid NULL in NOT IN lists.
Click to reveal answer
intermediate
Can IN and NOT IN be used with subqueries? Give an example.
Yes. Example: SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE active = 1);
Click to reveal answer
Which SQL operator checks if a value is inside a list of values?
✗ Incorrect
The IN operator checks if a value matches any value in a list.
What does NOT IN do in a SQL query?
✗ Incorrect
NOT IN excludes rows where the column's value is in the specified list.
What is the result if the list in NOT IN contains NULL?
✗ Incorrect
NOT IN with NULL in the list returns no rows because comparisons with NULL are unknown.
Which of these is a valid use of IN with a subquery?
✗ Incorrect
Option A correctly uses IN with a subquery to filter employees by active departments.
Which operator would you use to find rows where a column's value is NOT in a list?
✗ Incorrect
NOT IN filters out rows where the column's value is in the list.
Explain how the IN operator works and give a simple example.
Think about filtering rows by matching values.
You got /3 concepts.
Describe a potential issue when using NOT IN with NULL values in the list.
Consider how SQL treats NULL in comparisons.
You got /3 concepts.