Bird
0
0

Identify the mistake in the following self join query:

medium📝 Debug Q6 of 15
SQL - INNER JOIN
Identify the mistake in the following self join query:

SELECT e1.name, e2.name FROM employees e1 JOIN employees e2 ON e1.manager_id = e2.id WHERE e1.manager_id = NULL;
AMissing JOIN condition
BIncorrect table aliasing
CUsing '=' to compare with NULL instead of 'IS NULL'
DUsing JOIN instead of LEFT JOIN
Step-by-Step Solution
Solution:
  1. Step 1: Check WHERE clause

    The condition e1.manager_id = NULL is invalid because NULL cannot be compared with '='.
  2. Step 2: Correct NULL comparison

    Use IS NULL to check for NULL values in SQL.
  3. Final Answer:

    Using '=' to compare with NULL instead of 'IS NULL' -> Option C
  4. Quick Check:

    NULL comparisons require IS NULL [OK]
Quick Trick: Use IS NULL to check NULL values [OK]
Common Mistakes:
MISTAKES
  • Using '=' to compare NULL
  • Ignoring alias usage
  • Confusing JOIN types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes