mysql递归查询所有下级的sql
解决方法:
假如tb_manage_user表中uid是主键,creator_id是存储父级的uid,uid为10的所有子级和孙级,如果只想获取以逗号隔开的id串,查询返回字段中可以使用GROUP_CONCAT(uid),下面就是查询sql
select uid from (select t1.uid,if(find_in_set(creator_id, @pids) > 0, @pids := concat(@pids, ',', uid), 0) as ischild
from (select uid,creator_id from tb_manage_user t where 1=1) t1,(select @pids := 10) t2
) t3 where ischild != 0