RSS Feed

SQL CONNECT BY Example

SQL CONNECT BY Example


There is a table 'emp' with the data as shown below:
Table has data for 4 employees. A has no manager. B and C's manager is A. D's manager is B.

Lets write a query using CONNECT BY. CONNECT BY in general describes the relationship between parent row and child row in a hierarchy.
Below query lists all employees and their managers starting with top employee A who has no manager.
Below query lists all employees and their managers starting with manager with id as 1.
Below query lists all employees and their managers starting with manager with id as 2.