Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the table Employees ( id serial, name varchar ( 2 5 5 ) , manager id int ) ; In this table, manager is

Consider the table Employees (id serial, name varchar(255), manager id int);
In this table, manager is also an employee. Assume the CEO has no manager, but every other employee has one manager.
You want to write a query that gives all managers of a given employee with id =5.
SELECT e1.id, e1.name, e1.manager id FROM employees e1 INNER JOIN
employees e2 ON el.id = e2.manager id AND e2.id =5
WITH managerchain AS
SELECT id, name, manager_id FROM employees WHERE id =5
UNION ALL
SELECT e.id, e.name, e.manager_id FROM employees e INNER JOIN
managerchain m ON e.id = m.manager_id )
SELECT \" FROM managerchain;
SELECT id, name, manager id FROM employees WHERE id =5
WITH managerchain AS
SELECT id. name, manager id FROM employees

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions