Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:41:14+00:00 2026-05-22T17:41:14+00:00

I have the need to return tree like results from a single table. At

  • 0

I have the need to return tree like results from a single table. At the moment im using connect by and start with to ensure that all the correct results are returned.

select id,parent_id
     from myTable 
 connect by prior id = parent_id start with name = 'manager' 
     group by id, parent_id
 order by parent_id asc

However i want the results to return in tree structure. So each time a parent row is found its children rows will be displayed directly underneath it. Then move onto next parent and do the same

Expected results

  - Parent A
   - child a
   - child b 
  - Parent B
   - child c
   - child d 

Actual results

- Parent A 
- Parent B
- child a 
- child b 
- child c 
- child d

Is it possible to do this in oracle? My table uses a parent_id field to identify when a row has a parent. Every row also has a sort order, which is the order it should be sorted under its parent and a unique Id.

I’m using an Oracle DB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:41:14+00:00Added an answer on May 22, 2026 at 5:41 pm

    What you want is to use ORDER SIBLINGS BY. The query you have is ordering by the parent_id column which is overriding any hierarchical ordering.

    The query below should do what you need it to do:

    with my_hierarchy_data as (
      select 1 as id, null as parent_id, 'Manager' as name from dual union all
      select 2 as id, 1 as parent_id, 'parent 1' as name from dual union all
      select 3 as id, 1 as parent_id, 'parent 2' as name from dual union all
      select 4 as id, 2 as parent_id, 'child 1' as name from dual union all
      select 5 as id, 2 as parent_id, 'child 2' as name from dual union all
      select 6 as id, 3 as parent_id, 'child 3' as name from dual union all
      select 7 as id, 3 as parent_id, 'child 4' as name from dual 
    )
    select id, parent_id, lpad('- ', level * 2, ' ') || name as name
    from my_hierarchy_data
    connect by prior id = parent_id
    start with name= 'Manager'
    order siblings by parent_id asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have bunch of objects that return a DOM-tree that I then use to
I have a Linq provider that sucessfully goes and gets data from my chosen
Basically I have a asp.net that I need to display an XML document (straight
I have a big load of documents, text-files, that I want to search for
I need to implement a multi-parented tree (or digraph) onto SQL Server 2005. I've
I'm using Entity Framework 4.1 Code First. In my entity, I have three date/time
I have an XML document like this: <article> <author>Smith</author> <date>2011-10-10</date> <description>Article about <b>frobnitz</b>, crulps
I need to get all the folders and files from a folder recursively in
I've written an experimental function evaluator that allows me to bind simple functions together
I'm working on a webservices client app and I have it mostly working. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.