I have a simple table which has leafs and sub leafs info. ( like a forum questions)

A *main* message is defined where `childId` and `ParentID` are the same

![enter image description here](https://i.stack.imgur.com/039AP.png)

So here we see 2 main questions and their answers.

I've also managed to calc the depth of each element :

![enter image description here](https://i.stack.imgur.com/p6EcX.png)

In short this is the main query :

```
    WITH CTE AS
    (
       SELECT childID
             ,parentID,
             0 AS depth,name
       FROM   @myTable
       WHERE   childID = parentID AND childID=1 -- problem line

       UNION ALL

       SELECT TBL.childID
             ,TBL.parentID,
              CTE.depth + 1 , TBL.name 
       FROM   @myTable AS TBL
               INNER JOIN CTE  ON  TBL.parentID = CTE.childID
       WHERE   TBL.childID<>TBL.parentID
    )
    SELECT childID,parentID,REPLICATE('----', depth) + name        

```

But the problem is Line #8 (commented).

I currently ask *"give me all the cluster for question id #1"*

So where is the problem ?

I want to have **multiple** result set , for each question !

so here i need to have 2 result sets :

one for `childId=parentId=1`
and one for
one for `childId=parentId=6`

[**full working sql online**](https://data.stackexchange.com/stackoverflow/query/edit/127197)

*(and I dont want to use cursor)*