I have a table with following hypothetical data:
ID | Name | managerId
---|---------|-----------
1 | James | 2
2 | Martin | 4
3 | Huges | 5
4 | Richard | NULL
5 | Kavin | 4
6 | Rita | 3
In the above table we have:
Richard is manager of Martin is manager of James.
Richard is manager Kavin is manager of Huges is manager of Rita.
Now I have to select immediate manager and grand manager of an employee in this table. I mean if we start from Rita
I have to select Huges
(immediate manager) and Richard
(grand manager).
How to do that. I have no clue at all.
EDIT:
There isn't any specific levels of managers. An Employee can have 'n' Number for managers in hierarchy where n ϵ {0,1,2,3.....}