--树形sql查询 WITH TREE AS( --创建一个虚拟表 SELECT * FROM tableName --指定需要查询的表 WHERE id = '' -- 指定父节点条件 UNION ALL --联合查询 SELECT tableName.* FROM tableName,TREE WHERE TREE.id = tableName.parentId ) SELECT * FROM TREE;