Trying to understand Self Joins

Hi I’m currently learning self joins and I’ve got correct query and correct results but I don’t understand certain parts.

Firstly here is my table:

I’m using the self join to give me the name of the person that reports to a higher ranked person. Based on role and report to. So for example Grant would report to Daniel because supervisor answers to manager.

here’s my query:
SELECT m.Name AS ‘manager’,
e.Name AS ‘direct root’
FROM
customer e
INNER JOIN
customer m ON m.cust_id = e.ReportsTo
ORDER BY manager ASC

The results are :

The part I’m struggling to workout is how the second column is shown. For example I can’t workout how grant is displayed for daniel. Its correct but I just can’see how it gets to it?

Hopefully these circled screenshots help.

1 Like

There is already a column which corresponds to whom the employee is answerable to and those columns are joined together.

I still refer to this article whenever I need to refresh my memory of how JOINs work

1 Like

thank you for the kind words, Allan

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.