Hi, Let's say that I have a table with the following fields:
id (primary key, integer, auto inc.) name (varchar) parentID (int) The parentID field is used as a foreign key pointing to a parent record from the same table. Here is some sample data from the above-described table: *id* *name* *parentID* ==== ====== ========== 0001 abcdef 0000 0002 defghi 0000 0003 qwerty 0001 0004 tyuiop 0003 0005 tyooou 0001 0006 ghjklf 0003 What is the most efficient way to query the table to produce a treeview like the one below? abcdef |--qwerty |..|--tyuiop |..|--ghjklf |--tyooou defghi (hyphens above represent horizontal lines in the tree, while dots = no line) The table is expected to have thousands of records, so execution time could be an important factor.