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 6363545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:06+00:00 2026-05-25T00:03:06+00:00

In this scenerio… CREATE TABLE emp ( empno NUMBER(4) NOT NULL, ename VARCHAR2(10), job

  • 0

In this scenerio…

CREATE TABLE emp 
(
    empno  NUMBER(4) NOT NULL,
    ename  VARCHAR2(10),
    job    VARCHAR2(9),
    mgr    NUMBER(4),
    sal    NUMBER(7,2),
    deptno NUMBER(2)
);

INSERT INTO EMP VALUES(7782, 'CLARK', 'MANAGER', 7839, 2450, 10);
INSERT INTO emp VALUES(7369, 'SMITH', 'CLERK', 7902, 800, 20);
INSERT INTO EMP VALUES(7499, 'ALLEN', 'SALESMAN', 7698, 1600, 30);
INSERT INTO EMP VALUES(7521, 'WARD', 'SALESMAN', 7698, 1250, 30);
INSERT INTO EMP VALUES(7566, 'JONES', 'MANAGER', 7839, 2975, 20);
INSERT INTO EMP VALUES(7654, 'MARTIN', 'SALESMAN', 7698, 1250, 30);
INSERT INTO EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839, 2850, 30);
INSERT INTO EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566, 3000, 20);
INSERT INTO EMP VALUES(7839, 'KING', 'PRESIDENT', NULL, 5000, 10);
INSERT INTO EMP VALUES(7844, 'TURNER', 'SALESMAN', 7698, 1500, 30);
INSERT INTO EMP VALUES(7876, 'ADAMS', 'CLERK', 7788, 1100, 20);
INSERT INTO EMP VALUES(7900, 'JAMES', 'CLERK', 7698, 950, 30);
INSERT INTO EMP VALUES(7902, 'FORD', 'ANALYST', 7566, 3000, 60);
INSERT INTO EMP VALUES(7934, 'MILLER', 'CLERK', 7782, 1300, 10);

COMMIT;

SELECT LPAD(' ', 4  *(LEVEL - 1)) ||  empno || ' ' || mgr hier
   FROM emp
   start with mgr is null
   CONNECT BY PRIOR empno = mgr;

DROP TABLE emp;

The results look like this.

7839
    7566 7839
        7788 7566
            7876 7788
        7902 7566
            7369 7902
    7698 7839
        7499 7698
        7521 7698
        7654 7698
        7844 7698
        7900 7698
    7782 7839    
        7934 7782

It appears that during the connect by, the managers are ending up in ascending order.
Is there any way to control this behavior, so as to make them appear in descending order?

7839                  
    7782 7839         
        7934 7782   
    7698 7839         
        7900 7698   
        7844 7698     
        7654 7698     
        7521 7698     
        7499 7698     
    7566 7839         
        7788 7566     
            7876 7788 
        7902 7566     
            7369 7902 

Thanks

Evil

  • 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-25T00:03:06+00:00Added an answer on May 25, 2026 at 12:03 am

    Use the “ORDER SIBLINGS BY” clause to order siblings in the hierarchy.

    http://docs.oracle.com/database/121/SQLRF/queries003.htm

    SELECT LPAD(' ', 4  *(LEVEL - 1)) ||  empno || ' ' || mgr hier
       FROM emp
       start with mgr is null
       CONNECT BY PRIOR empno = mgr
       ORDER SIBLINGS by empno desc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The architecture for this scenario is as follows: I have a table of items
My scenerio is like this: At runtime, I bind ToolStripComboBox to array of struct:
Can someone please explain why this works. Here is the scenerio. I have a
How does one code this scenerio in iphone sdk? In an expense app, when
I have table data like this id id1 name 1 1 test1 1 1
I'm just tasked by my boss to create a Sharepoint solution for the scenerio
The scenerio is like this: I have to use multi-field query, which indexed several
My scenerio is like this: On the server there is an application which exposes
This is a difficult scenerio to explain, so I coded up a simple example.
This scenario comes up often, now that I use LinkToSql and the classes it

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.