Hi, All
I need an advice to build a query to a single table consisting of two columns: "THING", "PARENT OF THING".
This table describes tree-like hierarchy. The query should return all THINGs whose PARENT (direct, grand-, great-grand-, and so on) equals to, say, "Group_A":
Sample tree:
ROOT
|
+--Group_A
| |
| +--Sub_Aa
| | |
| | +--Sub_Sub_Aa1
| | | |
| | | +--thing P
| | | +--thing Q
| | |
| | +--thing R
| |
| +--thing S
|
+--Group_B
| |
. . . . . . and so on
The table describing this hierarchy is:
THING PARENT
=====================
Group_A ROOT
Sub_Aa Group_A
Sub_Sub_Aa1 Sub_Aa
thing P Sub_Sub_Aa1
thing Q Sub_Sub_Aa1
thing R Sub_Aa
thing S Group_A
Group_B ROOT
. . . . . . and so on
The result of query should be all subgroups and things nested inside Group_A, in spite of how deep:
THING
============
Sub_Aa
Sub_Sub_Aa1
thing P
thing Q
thing R
thing S
This would be no problem with subqueries if nesting level were limited to 2 or 3. But some THINGs and subgroups are 4 levels deep.
Can such nested membership be checked in SQL?
Best regards
I need an advice to build a query to a single table consisting of two columns: "THING", "PARENT OF THING".
This table describes tree-like hierarchy. The query should return all THINGs whose PARENT (direct, grand-, great-grand-, and so on) equals to, say, "Group_A":
Sample tree:
ROOT
|
+--Group_A
| |
| +--Sub_Aa
| | |
| | +--Sub_Sub_Aa1
| | | |
| | | +--thing P
| | | +--thing Q
| | |
| | +--thing R
| |
| +--thing S
|
+--Group_B
| |
. . . . . . and so on
The table describing this hierarchy is:
THING PARENT
=====================
Group_A ROOT
Sub_Aa Group_A
Sub_Sub_Aa1 Sub_Aa
thing P Sub_Sub_Aa1
thing Q Sub_Sub_Aa1
thing R Sub_Aa
thing S Group_A
Group_B ROOT
. . . . . . and so on
The result of query should be all subgroups and things nested inside Group_A, in spite of how deep:
THING
============
Sub_Aa
Sub_Sub_Aa1
thing P
thing Q
thing R
thing S
This would be no problem with subqueries if nesting level were limited to 2 or 3. But some THINGs and subgroups are 4 levels deep.
Can such nested membership be checked in SQL?
Best regards