SQL - SubqueriesWhich 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);Check Answer
Step-by-Step SolutionSolution:Step 1: Check syntax for IN with subqueryThe subquery must be enclosed in parentheses.Step 2: Validate correct comparisonThe column compared must be compatible with the subquery's returned column.Final Answer:SELECT name FROM Employees WHERE dept_id IN (SELECT dept_id FROM Departments); -> Option BQuick Check:Subquery must be in parentheses and return single column [OK]Quick Trick: Subquery with IN must be in parentheses [OK]Common Mistakes:MISTAKESOmitting parentheses around subqueryUsing = IN instead of INSelecting incompatible columns in subquery
Master "Subqueries" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Aggregate Functions - COUNT(*) vs COUNT(column) difference - Quiz 11easy GROUP BY and HAVING - WHERE vs HAVING mental model - Quiz 3easy INNER JOIN - Why joins are needed - Quiz 3easy INNER JOIN - INNER JOIN with table aliases - Quiz 5medium Set Operations - Set operation column matching rules - Quiz 1easy Table Constraints - Constraint naming conventions - Quiz 15hard Table Constraints - Foreign key ON DELETE behavior - Quiz 12easy Table Relationships - ER diagram to table mapping - Quiz 9hard Views - Views for security and abstraction - Quiz 15hard Views - CREATE VIEW syntax - Quiz 14medium