Bird
0
0

Which of the following is the correct way to write a subquery with the IN operator in SQL?

easy📝 Syntax Q3 of 15
SQL - Subqueries
Which of the following is the correct way to write a subquery with the IN operator in SQL?
ASELECT name FROM Employees WHERE dept_id = IN (SELECT dept_id FROM Departments);
BSELECT name FROM Employees WHERE dept_id IN (SELECT dept_id FROM Departments);
CSELECT name FROM Employees WHERE dept_id IN SELECT dept_id FROM Departments;
DSELECT name FROM Employees WHERE dept_id IN (SELECT dept_name FROM Departments);
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for IN with subquery

    The subquery must be enclosed in parentheses.
  2. Step 2: Validate correct comparison

    The column compared must be compatible with the subquery's returned column.
  3. Final Answer:

    SELECT name FROM Employees WHERE dept_id IN (SELECT dept_id FROM Departments); -> Option B
  4. Quick Check:

    Subquery must be in parentheses and return single column [OK]
Quick Trick: Subquery with IN must be in parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses around subquery
  • Using = IN instead of IN
  • Selecting incompatible columns in subquery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes