I'm using oracle database with hibernate. I have a EMPLOYEE table, with a self link back to itself on manager. Something like this:
create table employee(
id number(14) not null,
username varchar(100) not null unique,
manager number(14),
constraint employee_pk primary key (id),
constraint employee_manager_fk foreign key (manager) references employee (id)
);
Currently, I can select a employee and its direct child with:
select e2.*
from employee e2,
(select e.* from employee e where e.username='abc') e1
where e2.manager = e1.id
union
select e.* from employee e where e.username='abc'
I want to run a query where when given one employee username I can selected all it's child employees down to the n-th level. How do I do it in a SQL statement?