可以用如下sql语句实现。 select child_id from location_relation where parent_id=5 union select bbb.child_id from location_relation aaa,location_relation bbb where aaa.parent_id=5 and aaa.child_id=bbb.parent_id 注:mysql 4.0以上支持union语法。
to lordst(lordst),这样子只能找到两级吧,更多级怎么办
比如找第三级的child,可以用如下语句: select ccc.child_id from location_relation aaa,location_relation bbb,location_relation ccc where aaa.parent_id=5 and aaa.child_id=bbb.parent_id and bbb.child_id=ccc.parent_id 第四、第五级类似。是否有用一条sql就能select出全部子级别的数据?我想恐怕标准的sql语句做不到。是否如我所想,我也在等高手们指教。:)
select child_id from location_relation where parent_id=5 union select bbb.child_id from location_relation aaa,location_relation bbb where aaa.parent_id=5 and aaa.child_id=bbb.parent_id 注:mysql 4.0以上支持union语法。
select ccc.child_id from location_relation aaa,location_relation bbb,location_relation ccc where aaa.parent_id=5 and aaa.child_id=bbb.parent_id and bbb.child_id=ccc.parent_id
第四、第五级类似。是否有用一条sql就能select出全部子级别的数据?我想恐怕标准的sql语句做不到。是否如我所想,我也在等高手们指教。:)