SQL Exercise: Display employees and their 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 Adam Steven Payam Steven Shanta Steven Kevin Steven Julia Matthew Irene Matthew James Matthew Steven Matthew Laura Adam Mozhe Adam James Adam TJ Adam 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 Nandita Adam Alexis Adam Julia Adam Anthony Adam 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:

Practice Online
Query Visualization:
Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Display employees who have or have not any department.
Next SQL Exercise: Employees who work in the same department as Taylor.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
Count the number of occurrences of a string in a VARCHAR field?
SELECT title, description, ROUND ( ( LENGTH(description) - LENGTH( REPLACE ( description, "value", "") ) ) / LENGTH("value") ) AS count FROM <table>
Ref: https://bit.ly/3PvNdT4
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion