比较多的是存储过程的写法,这里只记录一下非存储过程的写法
select id from (
select t1.id,
if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
from (
select id,parent_id from re_menu t where t.status = 1 order by parent_id, id
) t1,
(select @pids := 要查询的菜单节点 id) t2
) t3 where ischild != 0
这里写得很详细: