1SELECT
2 e.first_name + ' ' + e.last_name employee,
3 m.first_name + ' ' + m.last_name manager
4FROM
5 sales.staffs e
6INNER JOIN sales.staffs m ON m.staff_id = e.manager_id
7ORDER BY
8 manager;
1Self is joining a table to itself.
2
3-- assume employee table as 2 different table using different alias
4-- as manager and worker
5-- we want to join these 2 virtual manager and worker table
6-- to get manager's first name and worker's first name
7-- our condition is worker's manager_id match managers employee id
8
9SELECT manager.FIRST_NAME AS MANAGER_NAME ,
10 worker.FIRST_NAME AS WORKER_NAME
11FROM EMPLOYEES manager
12INNER JOIN EMPLOYEES worker on worker.MANAGER_ID = manager.EMPLOYEE_ID
13
14order by 1
15;