Problem creating a complex query

A

Andre Beier

Hi,

I want to try to create the following recordset:

I want to create some kind of tree that starts out with one ID.
Every ID can have 5 or less PREVIOUSID's. Each of the PREVIOUSID's can have
up to 5 PREVIOUSID's. This goes on till all PREVIOUSID's are 0 for the final
record.

To make it easier to understand, here is one example:

ID | PREV01 | PREV02 | PREV03 | PREV04 | PREV05
1 0 0 0 0
0
2 1 0 0 0
0
3 0 0 0 0
0
4 2 3 0 0
0
5 0 0 0 0
0
6 0 0 0 0
0
7 0 0 0 0
0
8 6 5 4 0
0
9 0 0 0 0
0
....

Lets say a user queries for id = 8

I want to return a recordset that contains the follwing records:
8 - Requested by user
6,5,4 - PREVID's for record 8
2,3 - PREVID's for record 4
1 - PREVID for record 2

Thanks in advance.

Andre
 
Top