This is a follow up of the question: SQL Server to show a data tree in a specific format
Now we have a second table that is related to the first one on the "leaf" rows:
table1:
   Itemid   Itemname    Itemfatherid
    itemA    theitemA    null
    itemB    theitemB    null
    itemC    theitemC    itemA
    itemD    theitemD    itemA
    itemE    theitemE    itemC
    itemF    theitemF    itemE
    itemG    theitemG    itemD
In this table itemF and itemG would be leafs (they dont have any children)
table2:
   Itemid   RelItemid
    item1    itemF
    item2    itemF
    item3    itemG
The visual relation would be like this:
-itemA
    -itemC
        -itemE
            itemF (item1, item2)
    -itemD
        itemG (item3)
itemB
And we need to get all the rows from the 2nd table that are related to the first table filtering it by an especified node.
Examples:
Filtering by node itemA: item1, item2, item3
Filtering by node itemE: item1, item2
Filtering by node itemD: item3
Filtering by node itemG: item3
Filtering by node itemB: 
Sorry for the long post, its in order to cover any holes...thanks
 
     
    