Bird
0
0

Find the error in this query:

medium📝 Debug Q7 of 15
SQL - Subqueries
Find the error in this query:
SELECT emp_id FROM Employees WHERE dept_id IN (SELECT dept_name FROM Departments);
Aemp_id is not a valid column
BMissing WHERE clause in subquery
CIN operator cannot be used with subqueries
DSubquery returns dept_name but main query compares dept_id
Step-by-Step Solution
Solution:
  1. Step 1: Compare columns in main query and subquery

    Main query filters dept_id, but subquery returns dept_name, causing mismatch.
  2. Step 2: Identify type mismatch

    dept_id and dept_name are different types; comparison is invalid.
  3. Final Answer:

    Subquery returns dept_name but main query compares dept_id -> Option D
  4. Quick Check:

    Column types must match in IN subquery [OK]
Quick Trick: Ensure subquery returns same type as main query column [OK]
Common Mistakes:
MISTAKES
  • Returning wrong column in subquery
  • Ignoring data type mismatch
  • Assuming IN works with any column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes