Bird
0
0

Which of the following is the correct syntax to perform a self join on a table named employees with alias e1 and e2?

easy📝 Syntax Q12 of 15
SQL - INNER JOIN
Which of the following is the correct syntax to perform a self join on a table named employees with alias e1 and e2?
ASELECT * FROM employees e1 JOIN employees e2 ON e1.id = e2.manager_id;
BSELECT * FROM employees JOIN employees ON id = manager_id;
CSELECT * FROM employees e1, employees e2 ON e1.id = e2.manager_id;
DSELECT * FROM employees e1 INNER JOIN employees e2 ON e1.id = e2.id;
Step-by-Step Solution
Solution:
  1. Step 1: Use table aliases for self join

    To join a table to itself, you must use aliases like e1 and e2 to distinguish the two instances.
  2. Step 2: Write the join condition correctly

    The join condition should relate columns from the two aliases, for example e1.id = e2.manager_id to find employees and their managers.
  3. Final Answer:

    SELECT * FROM employees e1 JOIN employees e2 ON e1.id = e2.manager_id; -> Option A
  4. Quick Check:

    Self join syntax = table alias + join condition [OK]
Quick Trick: Always use aliases to distinguish the same table twice [OK]
Common Mistakes:
MISTAKES
  • Not using aliases causes syntax errors
  • Joining on wrong columns returns wrong results
  • Using comma join without aliases is confusing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes