I need to construct the query or function to solve my data structure problem.
My data struture only keep the parent node not the child node. Here the sample.
┌───────┐ ┌───────┐
Level-1 │ A │ │ B │ ────────► node is Unlimited
└───┬───┘ └───┬───┘
│ │
┌─────┴─────┐ ┌────┴──────┐
│ │ │ │
│ │ │ │
┌─────┴─┐ ┌───┴───┐ ┌───┴───┐ ┌──┴────┐
Level-2 │ C1 │ │ EE │ │ EF │ │ G1 │ ────────► node is Unlimited
└───┬───┘ └───────┘ └───┬───┘ └───┬───┘
│ │ │
┌──────────┴────────┐ │ ┌──┴─────────┐
Level-3 │ │ │ │ │
┌──┴────┐ ┌───┴───┐ ┌───┴───┐ ┌─┴─────┐ ┌───┴───┐
│ HH │ │ IU │ │ JK │ │ JA │ │ JJ │ ──► node is Unlimited
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘
│ │
Level-4 │ │
┌──┴────┐ ┌───┴───┐
│ OT │ │ │ PT │ ──► node is Unlimited
└───────┘ │ └───────┘
▼
Deep of level is unlimited
Table Node
+------+------+-------------+
| Rec# | Node | Parent_Node |
+------+------+-------------+
| 1 | A | |
| 2 | B | |
| 3 | C1 | A |
| 4 | EE | A |
| 5 | EF | B |
| 6 | G1 | B |
| 7 | HH | C1 |
| 8 | IU | C1 |
| 9 | JK | EF |
| 10 | JA | G1 |
| 11 | JJ | G1 |
| 12 | OT | HH |
| 13 | PT | JA |
+------+------+-------------+
The question is how to build query or function for retrieving data from this structure ?,.
For getting all data below the level.
Example :
from node A (level-1) => { the result should be: C1,EE,HH,IU,OT }
from node C1 (level-2) => { the result should be: HH,IU,OT }For getting just 1 level down, or several down of level.
Example :
Get 1 Level down, from node B (level-1) => { the result should be: EF and G1 Only}
Get 2 level down, from node G1 (level-2) => { the result should be: JA, JJ and PT }
Thank You.