mysql 根据父id查询下级所有数据

select

 id,apply_resource_name

from

 (

 select

 t1.id,t1.apply_resource_name,

 if(find_in_set(parent_id, @pids) > 0,

 @pids := concat(@pids, ',', id),

 0) as ischild

 from

 (

 select

  id,

  parent_id,

  apply_resource_name

 from

  resource_apply_resource t

 order by

  parent_id,

  id ) t1,

 (

  select @pids := 15) t2 ) t3

where

 ischild != 0

 

 

 

注释:@pids := 15的15就是要查询的父节点ID

posted @ 2023-03-03 18:58  JLCUI  阅读(530)  评论(0编辑  收藏  举报