Subject Iterating thru a tree-structure
Author Nols Smit
Hi,

I'm using a simple tree-structure with the following DDL:

CREATE TABLE LOCALITY (
ID INTEGER NOT NULL,
PARENT_ID INTEGER,
DESCRIPTION VARCHAR(50) NOT NULL
);

Typical data in this table will be:


ID Parent_ID Description
1 null South Africa
2 1 Limpopo
3 1 Gauteng
4 1 Eastern Cape
5 1 Western Cape
6 1 Northern Cape
7 1 Mpumalanga
9 1 KwaZulu-Natal
10 1 Free State
11 3 Pretoria
12 5 Bellville


The column ID is the primary key.

Those with a Parent_ID = 1 are provinces and those referring to provinces are cities, etc.

How do I iterate from a given primary key down through all the branches. I typically match a treeview in the program to the tree-structure and I want to show all the relevant records of a node and all its sub-nodes.


Regards,

Nols Smit


[Non-text portions of this message have been removed]