Remove assigned users from database table : <p>I have a table:</p>

<pre><code>| staff_id | leader_id |   team_role  | importance |
+          +           +              +            +
| 1001037  |  1000321  |      HOD     |      1     |
| 1001037  |  1000322  |      HOD     |      1     |
| 1001037  |  1001037  |  Supervisor  |      2     |
| 1001094  |  1001037  |    Checker   |      3     |
| 1001075  |  1001037  |    Checker   |      3     |
| 1001096  |  1001075  | Squad Leader |      4     |
| 1000393  |  1001094  | Squad Leader |      4     |
| 1000465  |  1001094  | Squad Leader |      4     |
| 1000585  |  1001075  | Squad Leader |      4     |
| 1000664  |  1000585  | Team Member  |      5     |
| 1000583  |  1000585  | Team Member  |      5     |
| 1000570  |  1000465  | Team Member  |      5     |
| 1000316  |  1000465  | Team Member  |      5     |
</code></pre>

<p>In php it look like this:</p>

<p><a href="https://i.stack.imgur.com/KPkZ9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KPkZ9.jpg" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/dOhSl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dOhSl.jpg" alt="enter image description here"></a></p>

<p>If I want to remove user with <code>staff_id = 1001075</code> I need to remove all assigned to this user ids. So it will be ids where <code>1001075</code> is <code>leader_id</code>. I am able to this but I also need to remove users going down to the tree so where <code>leader_id= 1001075</code> is will be <code>1000585</code> Then I need to remove users where <code>leader_id= 1000585</code></p>

<p>In the end I need to delete these users with <code>staff_id</code>:</p>

<pre><code>1001075
1001096
1000585
1000664
1000583
</code></pre>

<p>How can I do that?</p>
