Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the table Employees (id serial, name varchar(255), manager_id int); In this table manager is an employee. Assume the CEO has no manager, but every

image text in transcribed

Consider the table Employees (id serial, name varchar(255), manager_id int); In this table manager is 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 e1.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 UNION ALL SELECT e.id, e.name, e.manager_id FROM employees e INNER JOIN managerchain m ON m.id = e.manager_id) SELECT * FROM managerchain WHERE manager_id = 5

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

Students also viewed these Databases questions

Question

Describe the steps in the strategic communication research process.

Answered: 1 week ago

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago