I have data in the below format.
Emp to_location from_location Vehicle
---------------------------------------------
1 A B Road
1 B C Ship
1 C D Air
1 X D Bus
Need the output as
Emp ToL FromL Vehicle
--------------------------
1 A D Air
I tried using Connect by and Start with but the result is coming up as below.
Emp FromL ToL Path
--------------------------
1 B C Air
I need the output as
Emp FromL ToL Path
--------------------------
1 D A Air
The query I have built is like below.
with t as
( select 1 emp, 'A' tloc, 'B' floc, 'Road' v from dual union all
select 1 emp,'B' tloc, 'C' floc, 'Ship' v from dual union all
select 1 emp,'C' tloc, 'D' floc, 'Air' v from dual union all
select 1 emp,'X' tloc, 'D' floc, 'Bus' v from dual
)
select emp,
connect_by_root floc from_loc,
tloc to_location,
v,
CONNECT_BY_ISLEAF ch
from T
where CONNECT_BY_ISLEAF=1
CONNECT BY nocycle prior floc= tloc and prior emp=emp
AND PRIOR SYS_GUID() IS NOT NULL
START WITH tloc ='A'
Can anyone correct the minor thing that I am missing to get the correct output? TIA
I think your query is fine - you just to pick up the root element as you go
to then yield