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

  • SEARCH
  • Home
  • 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 7976869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:01:44+00:00 2026-06-04T09:01:44+00:00

I want hierarchical data for the test data given below. For user ‘jones’ it

  • 0

I want hierarchical data for the test data given below. For user ‘jones’ it should fetch the below records. I am having problem with CONNECT BY and START WITH clauses.
I also think there is some JOIN problem between menu_items AND role_menu_items tables.

for user and their corresponding roles i need to fecth below data

select  mi.id,  mi.NAME,mi.MEN_ID,mi.ICON,mi.ACTION--,r.NAME 
from
menu_items mi,
role_menu_items rmi,
roles r,
USERS U,
USER_ROLES UR
where
mi.ID=rmi.MIT_ID and
rmi.ROL_ID=r.id and
r.id=UR.ROLE_ID and
U.ID=UR.USER_ID and
U.NAME='jones'
start with mi.men_id is null
connect by   prior  mi.ID=mi.men_id

Output

1   Menu1           Menu1       /images/home.gif
3   Help            Help    
4   page1   a   1   page1   1   /images/email.gif
7   about   d   1   about   3

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (1,'Menu1',null,null,'Menu1',null,'/images/home.gif');

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (2,'Menu2',null,null,'Menu2',null,null);

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (3,'Help',null,null,'Help',null,null);

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (4,'page1','a',1,'page1',1,'/images/email.gif');

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (5,'page2','b',2,'page2',1,null);

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (6,'page3','c',1,'page3',2,'/images/photo.gif');

Insert into MENU_ITEMS (ID,NAME,SHORTCUT,DISPLAY_SEQUENCE,ACTION,MEN_ID,ICON) 
  values (7,'about','d',1,'about',3,null);

insert into ROLES (ID, NAME)
values (1, 'administrator');

insert into ROLES (ID, NAME)
values (2, 'user');

Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (1,4);
Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (1,5);
Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (1,6);
Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (1,7);
Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (2,4);
Insert into ROLE_MENU_ITEMS (ROL_ID,MIT_ID) values (2,7);

Insert into USER_ROLES (USER_ID,ROLE_ID) values (2,2);
Insert into USER_ROLES (USER_ID,ROLE_ID) values (1,1);
Insert into USER_ROLES (USER_ID,ROLE_ID) values (3,2);

Insert into USERS (ID,NAME,PASSWORD) values (2,'scott','scott');
Insert into USERS (ID,NAME,PASSWORD) values (1,'john','john');
Insert into USERS (ID,NAME,PASSWORD) values (3,'jones','jones');
  • 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-06-04T09:01:45+00:00Added an answer on June 4, 2026 at 9:01 am

    bad scheme, but it is possible

    1. select all menu_id for user role


    select RMI.MIT_ID
    from ROLE_MENU_ITEMS RMI
       , ROLES R
       , USERS U
       , USER_ROLES UR
    where RMI.ROL_ID = R.ID
      and R.ID = UR.ROLE_ID
      and U.ID = UR.USER_ID
      and U.NAME = 'jones'
    

    2. reverse hierarhy query


    select MI.*
         , max(LEVEL) over () + 1 - level as rev_level
         , lpad(' ', (max(LEVEL) over () + 1 - LEVEL) * 3, ' ') || MI.NAME as LEVEL_NAME
         , rownum RN
    from MENU_ITEMS MI
    connect by prior MEN_ID = ID
    start with ID IN (select RMI.MIT_ID
                      from ROLE_MENU_ITEMS RMI
                         , ROLES R
                         , USERS U
                         , USER_ROLES UR
                      where RMI.ROL_ID = R.ID
                        and R.ID = UR.ROLE_ID
                        and U.ID = UR.USER_ID
                        and U.NAME = 'jones')
    

    3. reverse (reverse hierarhy query)


    select ID
         , NAME
         , SHORTCUT
         , DISPLAY_SEQUENCE
         , ACTION
         , MEN_ID
         , ICON
         , LEVEL_NAME
    from 
    (
        select MI.*
             , max(LEVEL) over () + 1 - level as rev_level
             , lpad(' ', (max(LEVEL) over () + 1 - LEVEL) * 3, ' ') || MI.NAME as LEVEL_NAME
             , rownum RN
        from MENU_ITEMS MI
        connect by prior MEN_ID = ID
        start with ID IN (select RMI.MIT_ID
                          from ROLE_MENU_ITEMS RMI
                             , ROLES R
                             , USERS U
                             , USER_ROLES UR
                          where RMI.ROL_ID = R.ID
                            and R.ID = UR.ROLE_ID
                            and U.ID = UR.USER_ID
                            and U.NAME = 'jones')
    )
    group by ID --distinct with order
           , name
           , SHORTCUT
           , DISPLAY_SEQUENCE
           , ACTION
           , MEN_ID
           , ICON
           , LEVEL_NAME
    order by min(-RN)
    

    possible to keep the sort of root items by ID, using a subquery

    select ID
         , NAME
         , SHORTCUT
         , DISPLAY_SEQUENCE
         , ACTION
         , MEN_ID
         , ICON
         , LEVEL_NAME
    from 
    (
        select ID
             , NAME
             , SHORTCUT
             , DISPLAY_SEQUENCE
             , ACTION
             , MEN_ID
             , ICON
             , MAX(LVL) OVER () + 1 - LVL
             , rpad(' ', (max(LVL) over () + 1 - LVL) * 3, ' ') || NAME as LEVEL_NAME
             , RN
        from (
            select MI.*
                 , rownum RN
                 , level LVL
            from MENU_ITEMS MI
            connect by prior MEN_ID = ID
            start with ID IN (select RMI.MIT_ID
                              from ROLE_MENU_ITEMS RMI
                                 , ROLES R
                                 , USERS U
                                 , USER_ROLES UR
                              where RMI.ROL_ID = R.ID
                                and R.ID = UR.ROLE_ID
                                and U.ID = UR.USER_ID
                                and U.NAME = 'jones')
            order siblings by -ID
        )
    )
    group by ID --distinct with order
           , name
           , SHORTCUT
           , DISPLAY_SEQUENCE
           , ACTION
           , MEN_ID
           , ICON
           , LEVEL_NAME
    order by min(-RN)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch Hierarchical/Tree data something like below from a Table which has
I have the typical emp table from which i want to fetch the hierarchical
I have a scenario where I want to show hierarchical data in a DataGrid
Essentially, I want the user to be able to define a hierarchical model, but
I want to build a C# object from hierarchical XML data usinq LINQ. I
I'm working on a project where I have some hierarchical data that I want
i want to databind hierarchical data from plain data to the ASPxTreeList, i checked
Introduction: I have an AdvancedDataGrid displaying hierarchical data illustrated by the image below: The
I want to generate an hierarchical data representation, more like a family tree rather
Having the following hierarchical text data input (JunOS-like, in fact) I need to parse

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.