Interview Q&A / SQL & DBMS

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is a self join and when do you need one?

SHORT ANSWER

A self join joins a table to itself using two different aliases. It is used when rows relate to other rows in the same table, such as an employee and their manager.

Explain it simply

In a college, every student record may have a "class representative" who is also a student. The same list holds both the person and their representative. To show each name next to its representative, you look at the list twice: once as "student", once as "representative". That is a self join.

Example

Table employees(id, name, manager_id):

idnamemanager_id
1KavitaNULL
2Rohan1
3Priya1
4Aman2
sql
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.id;

Result:

employeemanager
KavitaNULL
RohanKavita
PriyaKavita
AmanRohan

LEFT JOIN keeps Kavita, who has no manager. An INNER JOIN would drop her.

What to say in the interview

"A self join treats one table as two by giving it two aliases. It fits hierarchies like employee-manager, or comparing rows within a table, such as pairs of flights on the same route. I use LEFT JOIN when the top of the hierarchy must stay in the result."

Common mistakes

  • Not aliasing, which makes column names ambiguous.
  • Using INNER JOIN and losing the root row.

#sql#joins#self-join

Related questions

Practise more SQL & DBMS questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open SQL & DBMS quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.