Skip to content
Advertisement

Defining the sort order of children in a hierarchy query

I would like to know the Oracle SQL query that orders the children in a hierarchy query by the sequence_within_parent column.

An example data set and query are:

This query returns the following:

The preferred output is below where the children are in the correct order:

Advertisement

Answer

The clause to be added to the query is “ORDER SIBLINGS BY SEQUENCE_WITHIN_PARENT”.

In the hierarchy all child nodes, or children, are referred to as siblings.

The full query for the example dataset is:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement