mysql 查询树结构数据 不使用递归查询

SELECT t1.* FROM tree t1, tree t2
WHERE t1.parent_id = t2.id
AND t2.id IN (
  SELECT t3.id FROM tree t3
  WHERE t3.id = <父节点id>
  UNION ALL
  SELECT t4.id FROM tree t4, tree t5
  WHERE t4.parent_id = t5.id AND t5.id = <父节点id>
);

你可能感兴趣的:(mysql 查询树结构数据 不使用递归查询)