I have table with ID who is PK and I have in same table column ParentID who is in some cases ID’s.(I say some cases because for example ParentID can be 0 but this ID not have in ID’s column).
I try to create Query:
ID ParentID Value
1 0 Test
2 0 Test01
3 2 Test02
4 3 Test03
And when I send ID=4 I need this result:
ID ParentID Value
2 0 Test01
3 2 Test02
4 3 Test03
Any help…
This looks like a tree traversal problem to me, which doesn’t lend itself particularly well to set-based operations. The following works, but it’s not too elegant: