Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Tree traversal in one line
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Tree traversal in one line
Miscellaneous
Thread ID:
00006281
Message ID:
00006281
Views:
92
Suppose I have a self-referential table as follows:
  ID  Name      Ref_ID
  --------------------
  01  Michel    00
  02  Tom       01
  03  Arnon     01
  04  Scot      02
  05  David     02
  06  John      03
  07  Bill      03
  08  Alistair  05
Where Ref_ID basically points to the person's 'sponsor' or
the person who referred the first person (like in a multi-level marketing scenario).

Now, say I wanted to get the IDs of sponsors for 'Alistair' all the way up to Michel (id 00 means no sponsor). This should be:
Alistair: 08, 05, 02, 01

Can this be done in one SQL statement? In one FoxPro statement? As in, one statement. No calls to stored procedures or functions, no compound statements or what.

Just curious...
alistair israel
Distressed DBA, Sleepy SysAd, Weary WebMaster (aka Senior Software Engineer)
aisrael@poboxes.com
Makati City, Philippines
Next
Reply
Map
View

Click here to load this message in the networking platform