I have a table like this...
==========================================================================
UID || PARENT ID || SPONSOR ID
==========================================================================
1 || 0 || 0
2 || 1 || 1
3 || 1 || 1
4 || 2 || 1
5 || 2 || 2
6 || 4 || 1
7 || 0 || 0
8 || 7 || 7
Lets say I am a user with UID = 1, now I want to query so I can get all of my nodes inside my network, how to query this table so I can get this result:
============================================================================
UID || PARENT ID || SPONSOR
============================================================================
2 || 1 || 1
3 || 1 || 1
4 || 2 || 1
5 || 2 || 2
6 || 4 || 1
I try to using this query
select @pv:=uid as uid, parentid,sponsorid from genealogy
join
(select @pv:=1)tmp
where parentid=@pv
But the result is only
============================================================================
UID || PARENT ID || SPONSOR
============================================================================
2 || 1 || 1
4 || 2 || 1
6 || 4 || 1
Whats wrong with my query.. anyone can help me? Thankyou very much