﻿ SQL JOINS on HR: Display the first name of all employees and the first name of their manager including those who does not working under any manager - w3resource

# SQL JOINS on HR Database: Display the first name of all employees and the first name of their manager including those who does not working under any manager

## SQL JOINS on HR Database: Exercise-11 with Solution

11. From the following table, write a SQL query to find the employees and their managers. These managers do not work under any manager. Return the first name of the employee and manager.

Sample table: employees

Sample Solution:

``````SELECT E.first_name AS "Employee Name",
M.first_name AS "Manager"
FROM employees E
LEFT OUTER JOIN employees M
ON E.manager_id = M.employee_id;
``````

Sample Output:

```Employee Name	Manager
Steven
Neena		Steven
Lex		Steven
Alexander	Lex
Bruce		Alexander
David		Alexander
Valli		Alexander
Diana		Alexander
Nancy		Neena
Daniel		Nancy
John		Nancy
Ismael		Nancy
Jose Manuel	Nancy
Luis		Nancy
Den		Steven
Alexander	Den
Shelli		Den
Sigal		Den
Guy		Den
Karen		Den
Matthew		Steven
Payam		Steven
Shanta		Steven
Kevin		Steven
Julia		Matthew
Irene		Matthew
James		Matthew
Steven		Matthew
Jason		Payam
Michael		Payam
Ki		Payam
Hazel		Payam
Renske		Shanta
Stephen		Shanta
John		Shanta
Joshua		Shanta
Trenna		Kevin
Curtis		Kevin
Randall		Kevin
Peter		Kevin
John		Steven
Karen		Steven
Alberto		Steven
Gerald		Steven
Eleni		Steven
Peter		John
David		John
Peter		John
Christopher	John
Nanette		John
Oliver		John
Janette		Karen
Patrick		Karen
Allan		Karen
Lindsey		Karen
Louise		Karen
Sarath		Karen
Clara		Alberto
Danielle	Alberto
Mattea		Alberto
David		Alberto
Sundar		Alberto
Amit		Alberto
Lisa		Gerald
Harrison	Gerald
Tayler		Gerald
William		Gerald
Elizabeth	Gerald
Sundita		Gerald
Ellen		Eleni
Alyssa		Eleni
Jonathon	Eleni
Jack		Eleni
Kimberely	Eleni
Charles		Eleni
Winston		Matthew
Jean		Matthew
Martha		Matthew
Girard		Matthew
Kelly		Payam
Jennifer	Payam
Timothy		Payam
Randall		Payam
Sarah		Shanta
Britney		Shanta
Samuel		Shanta
Vance		Shanta
Alana		Kevin
Kevin		Kevin
Donald		Kevin
Douglas		Kevin
Jennifer	Neena
Michael		Steven
Pat		Michael
Susan		Neena
Hermann		Neena
Shelley		Neena
William		Shelley
```

Pictorial Presentation:

## Query Visualization:

Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

﻿