Can any one suggest me how to get id of all children of a particular tree.
Table structure :
Table 1 : customer Table 2 : hierarchy
cId hId hId cId
1 1 1 null
2 2 2 null
3 3 3 2
4 4 4 3
5 5 5 2
6 6 6 5
7 7 7 7
Table (Customer) is the main element and table hierarchy only maintain the hierarchy of customer.
I have give cId 2
as root customer(parent). Now I have to get all cId
which are child of cId 2
(Given).
Expected Result of above scenario will be 2,3,4,5,6
(2 already given and these id set is customer ids). This is Actual answer that a query should return.
I looked for recursive query, procedure and by join but I am unable to get this result.
Applicable for Mysql, postgresql and sql server