Bird
0
0

Why does this query cause an error?

medium📝 Debug Q7 of 15
SQL - Advanced Joins
Why does this query cause an error?
SELECT e.name, m.name FROM employees e JOIN employees m ON e.manager_id = m.manager_id;
AThe SELECT clause is missing a GROUP BY
BThe table alias 'e' is not defined
CIt joins on manager_id to manager_id, which does not link employee to manager
DThe JOIN keyword is invalid here
Step-by-Step Solution
Solution:
  1. Step 1: Check join condition logic

    Joining on e.manager_id = m.manager_id matches employees with the same manager, not employee to manager.
  2. Step 2: Correct join condition needed

    To link employee to their manager, join on e.manager_id = m.id.
  3. Final Answer:

    It joins on manager_id to manager_id, which does not link employee to manager -> Option C
  4. Quick Check:

    Join keys must link employee to manager [OK]
Quick Trick: Join employee.manager_id to manager.id, not manager_id to manager_id [OK]
Common Mistakes:
MISTAKES
  • Joining on wrong columns
  • Assuming same manager_id means manager
  • Ignoring join logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes