I have a users table in this format:
| ID | PARENT |
| 1 | |
| 2 | 1 |
| 3 | 1 |
| 4 | 3 |
| 5 | 3 |
| 6 | 5 |
I wanted to create a query to verify if X is parent of Y. The examples i've found didn't help much as they don't work very well in multilevel hierarchy. Thanks for the help!
EDIT : the output can be the list of all parent of a node and in PHP I can check if the id is in the list.
I have tried this query:
select id,
parent_id
from (select * from users
order by parent_id, id) users_sorted,
(select @pv := '200911') initialisation
where find_in_set(parent_id, @pv) > 0
and @pv := concat(@pv, ',', id);
But it only works for ids that are superior to the one we are searching for. I have a special case where the parent id is superior to his child's