The answer of this post here provides one single query to find all ancestors of a node in a adjacency list.
Now, how do I find all decendants of a node using similar query? I tried:
SELECT @id :=
(
SELECT receiverid
FROM mytable
WHERE senderid = @id
) AS person
FROM (
SELECT @id := 5
) vars
STRAIGHT_JOIN
mytable
WHERE @id IS NOT NULL
I just swap senderid and receiverid, but it gives me #2014 Commands out of sync. You can't run this command now
.
Any idea?