I have the following table:
CREATE TABLE Z_BOM2 (A VARCHAR2(4 CHAR), B VARCHAR2(4 CHAR));
Insert into Z_BOM2 (A, B) Values ('A', 'B');
Insert into Z_BOM2 (A, B) Values ('A', 'C');
Insert into Z_BOM2 (A, B) Values ('C', 'D');
Insert into Z_BOM2 (A, B) Values ('C', 'F');
Insert into Z_BOM2 (A, B) Values ('D', 'E');
COMMIT;
SELECT * FROM Z_BOM2;
A B
A C
C D
C F
D E
A is a Parent and B is a child.
I would like to input child values 'E' and 'F' in a query and get only top level parents for both of those which should be 'A' for both of these. Here is the query I am using:
select SYS_CONNECT_BY_PATH (a,'/') as path, a, b, level, CONNECT_BY_ISLEAF AS leaf, CONNECT_BY_ROOT b top_level
from Z_BOM2
connect by prior a = b
start with b IN ('E', 'F');
Which returns the following:
/D D E 1 0 E
/D/C C D 2 0 E
/D/C/A A C 3 1 E
/C C F 1 0 F
/C/A A C 2 1 F
Why is it not returning correct top level parent ?