Connect by to get parents and grandparents

Help! I have this:
NAME LEVEL
Available System Menus 1
Authentication Setup 2
User Maintenance 3
Role Maintenance 3
App Maintenance 3
System Maintenance 3
User -> Role Maintenance 3
Role -> App Maintenance 3
App -> System Maintenance 3
9 rows selected.
THE DIFFICULTY: This query gets me my down-tree from (and including) #2, but how do I get the up-tree (#1, which may or may not include #2)
SELECT app_name,app_id,super_app_id
FROM my_applications
START WITH app_id = 2
CONNECT BY PRIOR app_id = super_app_id;
APP_NAME APP_ID SUPER_APP_ID
Authentication Setup 2 1
User Maintenance 3 2
Role Maintenance 4 2
App Maintenance 5 2
System Maintenance 6 2
User -> Role Maintenance 7 2
Role -> App Maintenance 8 2
App -> System Maintenance 9 2
8 rows selected.
ALREADY TRIED, got a connect by loop error, also did this with app_id=1:
SELECT app_name,app_id,super_app_id
FROM apex_applications
START WITH app_id = 2
CONNECT BY PRIOR super_app_id = app_id;

Hi,
gpoz wrote:
Help! I have this:
NAME LEVEL
Available System Menus 1
Authentication Setup 2 ...Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data.
THE DIFFICULTY: This query gets me my down-tree from (and including) #2, but how do I get the up-tree (#1, which may or may not include #2)
SELECT app_name,app_id,super_app_id
FROM my_applications
START WITH app_id = 2
CONNECT BY PRIOR app_id = super_app_id;If that query moves in one direction (up or down), then changing where PRIOR goes will move in the opposite direction.
(Of course, if you have loops in your data, then terms like "up" and "down" aren't very helpful.)
ALREADY TRIED, got a connect by loop error, also did this with app_id=1:
SELECT app_name,app_id,super_app_id
FROM apex_applications
START WITH app_id = 2
CONNECT BY PRIOR super_app_id = app_id;You did it correctly. The error is because of your data. Use CONNECT BY NOCYCLE to avoid that error.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0). This is especially important with CONNECT BY queries, because every version since Oracle 7 has had major improvements in this area.
See the forum FAQ {message:id=9360002}

Similar Messages

Maybe you are looking for

  • Resize Mail Window

    I have tried to point my arrow in the corner to resize the mail window.  Its too big.  It doesn't work.  It just wants to take action based on whatever is closest to the corner where I point the arrow.

  • HDV and Digital Cinema View.

    Hi I am using Digital Cinema View for playback of my timeline (View>All Frames) and the images seems to have traces (horizontal lines is best way I can describe) and text (like rendered Motion titles for example) looks poor too. My playback is set to

  • HTML DB1.6 installation --Kjell Ove, please reply :-)

    Hello, After installed the Oracle 10g db, I tried two ways to install html db: 1. in the oracle 10g bin directory, I click the sqlplus icon, then a dos terminal show up:(I enter the following info, and get the errors) Enter user-name: sysdba Enter pa

  • Ora-01552

    Hello all! All of a sudden i get the above error when i try to create a new table in my Oracle 9i database running on winXP. Cannot use system rollback segment for non-system tablespace 'TS_VAS_HR'. The tablespace exists. Wat cld b the problem. thnx

  • New version of Data Modeller?

    Any idea when the next version or patchset of Data Modeler will be released?