wvandenberg
Technical User
I have a self referencing table and I am trying to collect the selected record and all the records that are above it until I reach a ParentID that is null. The child could be at any level.
For example:
pkWaterUnitID,WaterUnit,ParentID
89,Wapasu Creek,79 <---Selected record
108,Wabasca River,NULL <---Selected record
79,Muskeg River,2
2,Athabasca River,NULL
So, of the two records I start with, one record does not have a parent (pkWaterUnitID=108). The other record(pkWaterUnitID=89) has a parent (pkWaterUnitID=79) that also has a parent (pkWaterUnitID=2).
Both the number and depth of the child will differ each time I run the query.
Should I build a select query for each level and then join them all in a union query? Is there a more efficient way? My head hurts %-)
Wendy
For example:
pkWaterUnitID,WaterUnit,ParentID
89,Wapasu Creek,79 <---Selected record
108,Wabasca River,NULL <---Selected record
79,Muskeg River,2
2,Athabasca River,NULL
So, of the two records I start with, one record does not have a parent (pkWaterUnitID=108). The other record(pkWaterUnitID=89) has a parent (pkWaterUnitID=79) that also has a parent (pkWaterUnitID=2).
Both the number and depth of the child will differ each time I run the query.
Should I build a select query for each level and then join them all in a union query? Is there a more efficient way? My head hurts %-)
Wendy