An Oracle query from a subnode to a parent node

Source: Internet
Author: User

Today, a person in the department asked me how to trace data from a subnode record to a parent node in Oracle. For example, there is a table:

Guid parentguid

1 0

2 1

3 1

4 2

5 2

6 5

7 5

8 7

We can find all the sub-nodes under the guid Based on the parentguid relationship.

If the guid of a subnode is 7, you need to find out its parent node, which is 7-> 5-> 2-> 1.

In fact, this is a very funny question. If you can find the child node from the parent node, then in turn, use the guid of the child node as the parentguid of the parent node.

The child node becomes the parent node.

Select guid from Test start with guid = 7 connect by prior parentguid = guid

You can find the relationship between 7-> 5-> 2-> 1.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.