0

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
luca ditrimma
  • 765
  • 1
  • 7
  • 22
  • if they had the same boos_id it would be simple but how should a query know that id 0 is linked with 7 6 and 5 or is the only one boss? – nbk Jul 19 '19 at 17:01
  • there will be more boss at level 3 which are having another leaders (level 2) with their own users – luca ditrimma Jul 19 '19 at 17:04

0 Answers0