Joins · SQL SQL

Which of the following queries demonstrates a self-join?

Practice question from Joins (SQL SQL), with the correct answer and a step-by-step solution.

medium · MCQ · Q-25A2A0

Which of the following queries demonstrates a self-join?

  1. A.SELECT * FROM employees JOIN departments ON employees.dept_id = departments.id;
  2. B.SELECT e1.name, e2.name FROM employees e1 JOIN employees e2 ON e1.manager_id = e2.id;Correct answer
  3. C.SELECT * FROM employees CROSS JOIN contractors;
  4. D.SELECT * FROM employees NATURAL JOIN salaries;

Solution

A self-join is a regular join where a table is joined to itself, typically using table aliases (like e1 and e2) to distinguish between the two instances of the table, often used for hierarchical data like employee-manager relationships.

More from Joins

All of Joins

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed