Write SQL query as mentioned below: you can see the numbers indicate the relationship between each node.

As you can see the numbers indicate the relationship between each node. All left values greater than 6 and right values less than 11 are descendants of  6-11 (i.e Id: 3 Amanda). Now If you want to extract out the 2-6 sub-tree for Amanda. What SQL query you will write?

SELECT * FROM employee WHERE left_val BETWEEN 6 and 11 ORDER BY left_val ASC;

To extract the sub-tree rooted at the node with ID 2-6 for Amanda, you would typically use a recursive common table expression (CTE) if your DBMS supports it. Here’s how you can write the SQL query:

sql
WITH RECURSIVE SubTree AS (
SELECT *
FROM YourTableName
WHERE Id = '2-6' AND Name = 'Amanda'
UNION ALLSELECT t.*
FROM YourTableName t
JOIN SubTree s ON t.ParentId = s.Id
)
SELECT *
FROM SubTree;

Replace YourTableName with the name of your table containing the hierarchical data. This query will retrieve all rows that are descendants of node ‘2-6’ for Amanda, including ‘2-6’ itself. Make sure your DBMS supports recursive queries if you plan to use this syntax.