如何在MySQL中选择树状结构的所有子级 [英] How to select all child of a tree structure in MySQL

查看:94
本文介绍了如何在MySQL中选择树状结构的所有子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,树的结构如下:

Int => ID [主键]
varchar =>名称
Int => ParantId [RefKey:-引用ID]

现在我要做的是:通过选择任何名称,我需要我选择的名称下的所有子项和子子项,而不是来自与之平行或高于所选名称的其他名称,我写了以下查询:

i have table with following structure for a tree:

Int => Id [Primary key]
varchar => Name
Int => ParantId [RefKey:-Ref to Id]

now i want to do is: by selecting any name, i need all the childs and sub child under the name that i selected and not from other names which are parallel or above the selected name, i wrote following query:

SELECT GROUP_CONCAT(o2.Id SEPARATOR '','')
    FROM organization AS o1, organization AS o2
    WHERE o1.Id = o2.ParentOrganizationId
        AND (o1.Id=3 OR o1.ParentOrganizationId =3));



但是它不起作用!!有人可以帮我吗?

在此先感谢:-)



but it is not working!! can any one help me?

thanks in advance:-)

推荐答案

杜莎(Hi Tushar),
HierarchyTree [
Hi Tushar,
HierarchyTree[^]
I hope it can give you a solution.


这篇关于如何在MySQL中选择树状结构的所有子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆