Bird
0
0

Which of the following is the correct syntax for aliasing tables in a self join?

easy📝 Syntax Q3 of 15
SQL - INNER JOIN
Which of the following is the correct syntax for aliasing tables in a self join?
ASELECT employees.id, employees.manager_id FROM employees JOIN employees ON employees.manager_id = employees.id
BSELECT a.id, b.id FROM employees a JOIN employees b ON a.manager_id = b.id
CSELECT id, manager_id FROM employees WHERE id = manager_id
DSELECT * FROM employees AS e1, employees AS e2 WHERE e1.id = e2.manager_id
Step-by-Step Solution
Solution:
  1. Step 1: Check alias usage in self join

    Aliasing tables with short names like 'a' and 'b' helps distinguish the same table used twice.
  2. Step 2: Verify join condition and syntax

    SELECT a.id, b.id FROM employees a JOIN employees b ON a.manager_id = b.id correctly aliases and joins employees on manager_id matching id.
  3. Final Answer:

    SELECT a.id, b.id FROM employees a JOIN employees b ON a.manager_id = b.id -> Option B
  4. Quick Check:

    Correct alias syntax = SELECT a.id, b.id FROM employees a JOIN employees b ON a.manager_id = b.id [OK]
Quick Trick: Use aliases to differentiate tables in self join [OK]
Common Mistakes:
MISTAKES
  • Not aliasing tables
  • Using WHERE instead of JOIN
  • Incorrect join condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes