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. Write a query in SQL to display the first name of all employees and the first name of their manager including those who does not working under any manager.
Sample table: employees
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;
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
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have not any department.
Next: Write a query in SQL to display the first name, last name, and department number for those employees who work in the same department as the employee who hold the last name as Taylor.
What is the difficulty level of this exercise?