I have a tree view in the table mysql on the basis of id, depth, parent_idand path. Each root entry in this table has a depth of view 0, parent_id != nulland pathbased on the hexadecimal value of the identifier populated on the left with 0.
Each item in the tree created by specifying depth = parent.depth + 1, path = parent.path + hex(id), parent_id = parent.id(pseudo), eg:
id path depth parent_id assigned_user_id
------------------------------------------------------------
1 001 0 NULL NULL
2 002 0 NULL 1
3 001003 1 1 2
4 002004 1 2 1
5 001003005 2 3 2
6 001003005006 3 5 2
7 002004007 2 4 1
8 002004008 2 4 2
9 002004009 2 4 2
10 00200400800A 3 8 2
and so on ... The problem is how to get entries for a specific user ID, limited to the shortest path in the same branch . For example, to assigned_user_id = 2extract:
id path depth parent_id assigned_user_id
------------------------------------------------------------
3 001003 1 1 2
8 002004008 2 4 2
9 002004009 2 4 2
Instead:
id path depth parent_id assigned_user_id
------------------------------------------------------------
3 001003 1 1 2
5 001003005 2 3 2
6 001003005006 3 5 2
8 002004008 2 4 2
9 002004009 2 4 2
10 00200400800A 3 8 2