What is a database?

A Database is a logical, consistent and organized collection of data that it can easily be accessed, managed and updated. Databases, also known as electronic databases are structured to provide the facility of creation, insertion, updating of the data efficiently and are stored in the form of a file or set of files, on the … Read more

What is DBMS?

DBMS is a collection of programs that facilitates users to create and maintain a database. In other words, DBMS provides us an interface or tool for performing different operations such as the creation of a database, inserting data into it, deleting data from it, updating the data, etc. DBMS is a software in which data … Read more

Which will return: Peter and Amanda

If you want to find out the number of descendants for a node, all you need is the left_val and right_val of the node for which you want to find the  descendants  count. The formula is No. of descendants = (right_val – left_val -1) /2 So,  for 6 -11 Amanda, (11 – 6 – 1) /2 =  2 … Read more

Which will return Amanda, Ralph, and Jeanne. If you want to get ancestors to a given node say 7-8 Ralph. What SQL query you will write?

SELECT * FROM employee WHERE left_val < 7 and right_val > 8 WHERE ORDER BY left_val ASC; To retrieve ancestors of a given node in a hierarchical structure stored in a database using SQL, you typically use recursive queries, which are supported by some relational database management systems (RDBMS) like PostgreSQL, SQL Server, and Oracle. … Read more

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 … Read more