Hi,
A simple way is to make a recursive search by starting from the root, and collecting all ID's from each layer. You need only one query per layer, not one per node. It looks like this : -> start from the desired "directory" : SELECT * FROM table WHERE id_parent IN (8) -> say it returns children ids 4,5,12, then : SELECT * FROM table WHERE id_parent IN (4,5,12) and so on until the query returns an empty result set, which simply means the search has ended. If you really have a big tree, though, there is another way, less intuitive, which is described here : http://www.mip.berkeley.edu/mip/related/thesaurus/thesaurus.pdf Yours > Hi, > can someone suggest the best way to perform a query that > extract from a category table all the structure, like a filesystem? For > example, I've a table of categorie like this: > ID name descr ID_parent > and I've assigned -1 to the root category. > I'd like to draw a directory-like structure (like windows explorer), > but I don't know how to extract a directory name, and all sub-directory > recursively. --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php