Which of the following is the correct syntax to use a subquery with the IN operator?
easy📝 Syntax Q12 of 15
SQL - Subqueries
Which of the following is the correct syntax to use a subquery with the IN operator?
ASELECT * FROM employees WHERE IN department_id (SELECT id FROM departments);
BSELECT * FROM employees WHERE department_id = IN (SELECT id FROM departments);
CSELECT * FROM employees WHERE department_id IN (SELECT id FROM departments);
DSELECT * FROM employees WHERE department_id IN SELECT id FROM departments;
Step-by-Step Solution
Solution:
Step 1: Review correct IN syntax
The IN operator must be followed by parentheses enclosing the subquery.
Step 2: Check each option
SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments); correctly uses IN with parentheses and a subquery. Options A, B, and D have syntax errors.
Final Answer:
SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments); -> Option C
Quick Check:
IN syntax = IN (subquery) [OK]
Quick Trick:Use parentheses around subquery after IN [OK]
Common Mistakes:
MISTAKES
Adding = before IN
Missing parentheses around subquery
Placing IN before column name
Master "Subqueries" in SQL
9 interactive learning modes - each teaches the same concept differently