数据库
首页 > 数据库> > mysql 树查询 递归查询 查询选中id下的所有数据

mysql 树查询 递归查询 查询选中id下的所有数据

作者:互联网

id  ,parent_id 上下级的定义

select id from (
               select t1.id,t1.parent_id,
               if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
               from (
                    select id,parent_id from sys_org t where t.del_flag = '0' order by parent_id, id
                   ) t1,
                   (select @pids := '1') t2
              ) t3 where ischild != 0;

标签:parent,查询,mysql,pids,t1,id,select
来源: https://www.cnblogs.com/ljj007/p/16267003.html