Tree structure solution in mysql
Posted: Wed Apr 22, 2009 8:59 am
I have one table which has three fields. MId Name and ParentId.
Suppose i have following table.
MId Name ParentId
1 a 0
2 a1 1
3 a2 1
4 a3 1
5 a4 1
6 a11 2
7 a12 2
8 a13 2
9 a111 6
10 a112 6
11 a113 6
12 a1111 9
13 a1112 9
14 a1113 9
15 a1114 9
Above table shows the MId(memberid), membername and parent of member.
I want to get all the child of particular member.
Suppose i have Mid=2 then we can get all the childs and subchilds of MId 2.
We can get result in following format.
Parent Child
a1 a11
a1 a12
a1 a13
a11 a111
a11 a112
a11 a113
a111 a1111
a111 a1112
a111 a1113
a111 a1114
I need solution of this question as soon as possible.
please help me.
Thanks in advance
Suppose i have following table.
MId Name ParentId
1 a 0
2 a1 1
3 a2 1
4 a3 1
5 a4 1
6 a11 2
7 a12 2
8 a13 2
9 a111 6
10 a112 6
11 a113 6
12 a1111 9
13 a1112 9
14 a1113 9
15 a1114 9
Above table shows the MId(memberid), membername and parent of member.
I want to get all the child of particular member.
Suppose i have Mid=2 then we can get all the childs and subchilds of MId 2.
We can get result in following format.
Parent Child
a1 a11
a1 a12
a1 a13
a11 a111
a11 a112
a11 a113
a111 a1111
a111 a1112
a111 a1113
a111 a1114
I need solution of this question as soon as possible.
please help me.
Thanks in advance