Bird
0
0

Identify the error in this self join query:

medium📝 Debug Q14 of 15
SQL - INNER JOIN
Identify the error in this self join query:
SELECT e1.name, e2.name FROM employees e1 JOIN employees e2 ON e1.id = e2.id;
AMissing table aliases for employees
BUsing JOIN instead of LEFT JOIN causes error
CSyntax error due to missing WHERE clause
DThe join condition compares the same column, causing incorrect results
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the join condition

    The query joins employees to itself on e1.id = e2.id, which matches each row to itself only, not to related rows.
  2. Step 2: Understand the effect of the condition

    This join condition does not find relationships like manager or pairs; it just duplicates rows, which is likely incorrect for self join use.
  3. Final Answer:

    The join condition compares the same column, causing incorrect results -> Option D
  4. Quick Check:

    Self join needs meaningful join condition, not same column equals [OK]
Quick Trick: Join condition must relate different columns for meaningful self join [OK]
Common Mistakes:
MISTAKES
  • Joining on identical columns returns only same rows
  • Forgetting to use aliases
  • Assuming JOIN requires WHERE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes