1
I have the following query
    select  id,
        nome,
        user_id
from    (select * from users
         order by user_id, id) users,
        (select @pv := '2') initialisation
where   find_in_set(user_id, @pv) > 0
and     @pv := concat(@pv, ',', id)
union
select  id,
        nome,
        user_id
from users where id = 2
And here are some fake values for this table.
ID  NAME        USER_ID
1   Main User   0
2   User A      1
3   User B      1
4   User C      2
5   User D      2
6   User E      2
7   User F      4
8   User G      4
9   User H      1
10  User I      1
11  User J      2
The query works, but I need the results to be nested and sorted by user level.
In the query example, I passed ID 2, so the result should come like this:
2. User A
 ___ 4. User C
    ___ 7. User F
    ___ 8. User G
 ___ 5. User D
 ___ 6. User E
 ___ 11. User J
Can be with __ in the result, no problem. The important thing is to have this tree scheme.
Thank you.


What version of MYSQL ?
– Rovann Linhalis
Relevant: https://answall.com/a/193833/64969
– Jefferson Quesado