with empcte as
(
select eid,name,mgrid,2 as level from employee where eid=102
union all
select usr.eid,usr.name,usr.mgrid,level-1 from empcte as mgr inner join employee usr on mgr.mgrid=usr.eid
)
select * from empcte as u;
Given below is the employee table with its data and below that is the resultset of the above query.
(
select eid,name,mgrid,2 as level from employee where eid=102
union all
select usr.eid,usr.name,usr.mgrid,level-1 from empcte as mgr inner join employee usr on mgr.mgrid=usr.eid
)
select * from empcte as u;
Given below is the employee table with its data and below that is the resultset of the above query.
No comments:
Post a Comment