Hello Arun,
if the recursion is not too deep, then one of the possible options is to store all the "previous" manager ids in a separate column, and then filter by that column, like this:
with recursive recursive_T3(manager,reportee,loopno, manager_list)
as
(
sel B.manager ,
B.reportee ,
0,
'('||trim(b.manager)||')' as manager_list
from T3 as B
where B.reportee = 5
union all
sel B.manager ,
T2.reportee ,
T2.loopno+1,
T2.manager_list || '('||trim(b.manager)||')' as manager_list
from T3 as B, recursive_T3 T2
where B.reportee = T2.manager
and position ( '('||trim(B.manager)||')' IN T2.manager_list ) =0
and T2.loopno <= 100
)
sel * from recursive_T3 where loopno = (sel max(loopno) from recursive_T3);
Regards,
Vlad.
Hello Arun,
if the recursion is not too deep, then one of the possible options is to store all the "previous" manager ids in a separate column, and then filter by that column, like this:
with recursive recursive_T3(manager,reportee,loopno, manager_list)
as
(
sel B.manager ,
B.reportee ,
0,
'('||trim(b.manager)||')' as manager_list
from T3 as B
where B.reportee = 5
union all
sel B.manager ,
T2.reportee ,
T2.loopno+1,
T2.manager_list || '('||trim(b.manager)||')' as manager_list
from T3 as B, recursive_T3 T2
where B.reportee = T2.manager
and position ( '('||trim(B.manager)||')' IN T2.manager_list ) =0
and T2.loopno <= 100
)
sel * from recursive_T3 where loopno = (sel max(loopno) from recursive_T3);
Regards,
Vlad.