>I have a table that contains a number of items. Each record has a primary Key and a Foreign Key to itself representing a parent/child relationship. For example:
>
>
>pkey fkey title
>1 null line 1
>2 1 line 2
>3 1 line 3
>4 2 line 4
>5 2 line 5
>6 4 line 6
>
>etc...
>What I have spent a long time trying to figure out is how to construct a SQL Query that will extract the table structure in order preserving all parent/children. That is a parent and all its children in order. the final output should look like a tree structure.
>
>ie (just for show):
>
>line 1
> line 2
> line 4
> line 6
> line 5
>
>It should really be a series of record2 with the pkey i.e.
>
>1
>2
>4
>6
>5
>etc...
>
>I have tried a number of left joins on the table itself to itself, but this doesn't give me a true representation of the tree. I can't think of any way else to do this, but I'm sure there must be a way. Please help me if you can.
>
>Thanks..
TreeView stracture could be created in this way
ChildID parentID title level
1 null line 1 0
2 1 line 2 1
3 1 line 3 1
4 2 line 4 2
5 1 line 5 1
6 2 line 6 2
>
HTH