Mysql Recursive Subquery
Not sure the title accurately reflects what I need to do and this question is possibly out of the scope of Stack Overflow as I do not have much to work with, other than my problem.
Solution 1:
i'm not sure if herachial data is what you need/want, but here's what you need
all tops, middle, an regular members, DEMO, SQL :
select
IFNULL((SELECT name FROM users where uid=smng.leader_id),(SELECT name FROM users where uid=mng.leader_id))
as top,
(SELECT name FROM users where uid = mng.leader_id)
as middle,
usr.name as regular
from
users usr inner join managers mng on usr.uid=mng.member_id
inner join managers smng on mng.leader_id = smng.member_id
for specified top manager add :
where smng.leader_id =1
for a specified middle manager change to :
where mng.leader_id =2
Post a Comment for "Mysql Recursive Subquery"