--通过子节点查询父节点WITH TREE AS( SELECT * FROM tstructure WHERE id = 6 -- 要查询的子 id UNION ALL SELECT tstructure.* FROM tstructure, TREE WHERE TREE.parent = tstructure.id ) SELECT * FROM TREE--通过父节点查询子节点WITH TREE AS( SELECT * FROM tstructure WHERE parent = 2 -- 要查询的父 id UNION ALL SELECT tstructure.* FROM tstructure, TREE WHERE tstructure.parent = TREE.id ) SELECT * FROM TREE
来一个我现实中用到的代码吧
( . url .. ., tree TREE.fid . tree code
摘:http://www.cnblogs.com/cracker/archive/2012/07/07/2580781.html
转载于:https://blog.51cto.com/zhaoyingyatou/1600030