I don't know how to describe this problem using exact technical phrases. But this is the scenario for the problem.
Below is my table which consists of 3 levels of users. Normally, I can achieve my expected result by using loop in code. I need to know is there a simple way to achieve this at database level.
id| name | level | boss_id |
--|----------|--------|----------|
1 | User A | 1 | 5 |
2 | User B | 1 | 5 |
3 | User C | 1 | 6 |
4 | User D | 1 | 6 |
5 | Leader A | 2 | 7 |
6 | Leader B | 2 | 7 |
7 | Boss A | 3 | 0 |
When I look up for Boss A, I want to be able to list all users which are linked to leaders (Leader A & Leader B) attached to Boss A. The result would be:
User A
User B
User C
User D