13. Hierarchical Queries
Expressing a Parent-Child Relationship
We want to include parent information along with data from child records. For example, we want to display each employee’s name along with the name of their manager.
Sample Output
Expressing a Child-Parent-Grandparent Relationship
We want to find Manager of a Manager of an employee. For example, Employee CLARK works for KING, and CLARK was in turn a manager for another employee SHARK. (Three-Tier Relationship)
SHARK -> CLARK -> KING
Creating a Hierarchical View of a Table
In the case of the EMP table, employee KING has no manager, so KING is the root node. You want to display, starting from KING, all employees under KING and all employees (if any) under KING’s subordinates.
Sample Output
Finding All Child Rows for a Given Parent Row
We want to find all the employees who work for JONES, either directly or indirectly.
Sample Output
Determining Which Rows Are Leaf, Branch, or Root Nodes
We want to determine what type of node a given row is: a leaf, branch, or root.
Sample Output
Last updated