Cindy,
>That being said, I don't have enough information (or maybe just brain power) to see the pattern.
SID Desc PID LX
1....A....0....0
3....B....1....1
5....C....3....2
7....D....5....3
14...F....3....2
8....E....14...3
21...G....3....2
22...H....21...3
The PID in line 2 (value 1) follows the line with SID of 1 (line 1) and is at the first level (LX=1) in the tree. This is followed on line 3 with the first Level 2 record with PID=3 to correspond to the SID of line 2.
That pattern continues down the tree with each line increasing in Level (LX) until there are no more. Then, you'd look back up the tree for other records where the PID matches an SID on the next higher level or even higher if none found at that level.
You see this in line 5, when you get a second Level 2 record with PID=3 corresponding to the SID=3 on Level 1 in line 2.
I don't have any idea how to do this in a SELECT statement, however. :-)