For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
SELECT * FROM table_x WHERE CONNECT_BY_ISLEAF = 1 AND LEVEL = 1 START WITH parent_id IS NULL CONNECT BY parent_id = PRIOR id AND LEVEL <= 2 -- For efficiency ;
SQL> ed Wrote file afiedt.buf 1 with t as (select null as mgr, 1 as emp_id, 'Chairman' as position from dual union all 2 select 1, 2, 'Vice Chairman' from dual union all 3 select 2, 3, 'Company Director' from dual union all 4 select 3, 4, 'Sales Manager' from dual union all 5 select 3, 5, 'Technology Manager' from dual union all 6 select 3, 6, 'HR Manager' from dual union all 7 select 4, 7, 'Sales Rep' from dual union all 8 select 4, 8, 'Sales Rep' from dual union all 9 select 4, 9, 'Sales Rep' from dual union all 10 select 10, 10, 'Dodgy Contractor' from dual union all 11 select 5, 11, 'Software Developer' from dual union all 12 select 5, 12, 'Software Developer' from dual union all 13 select 5, 13, 'Network Specialist' from dual union all 14 select 5, 14, 'Communications Implementer' from dual union all 15 select 6, 15, 'Rectruitment Agent' from dual union all 16 select 6, 16, 'Job Marketing Agent' from dual union all 17 select 6, 17, 'Job Marketing Assistant' from dual) 18 -- 19 -- END OF TEST DATA 20 -- 21 select emp_id from t 22 minus 23 select emp_id 24 from t 25 connect by mgr = prior emp_id 26* start with mgr is null SQL> / EMP_ID ---------- 10 SQL>
SELECT EMPNO FROM SCOTT.EMP WHERE EMPNO NOT IN ( SELECT EMPNO FROM SCOTT.EMP CONNECT BY PRIOR EMPNO=MGR START WITH MGR = 7566 )