If the depth of the tree is always the same, it is actually fairly easy. For instance, if there are three levels:
SELECT c.group_id FROM table a, table b, table c WHERE a.group_id = 12345 AND b.group_id = a.parent_group_id AND c.group_id = b.parent_group_id If you don't know the depth, you'll have to do a recursive search (keep on querying for the next parent until you run out of parents). Steve Meyers > -----Original Message----- > From: Daniel Łaś [mailto:[EMAIL PROTECTED]] > Sent: Monday, October 22, 2001 3:34 PM > To: Lista MySQL > Subject: Tree in SQL > > > Hi > > I have a table in database which describes tree structure of > article groups. > In this table I have: > 1. group_id - group identifier > 2. parent_group_id - identifier of parent group > I need to select history, from top to wanted group. > I can't change the database design and ofcourse this is MySQL > 3.23 database. > Can somebody help me ? > > Thanks > > ____________________________________ > Daniel Łaś > e-direct Polska sp. z o.o. > WWW: http://www.e-direct.pl > E-mail: [EMAIL PROTECTED] > 45-072 Opole ul. Reymonta 45 > tel. +48 77 44 26 073 > fax. +48 77 44 26 074 > > > --------------------------------------------------------------------- > 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 > > --------------------------------------------------------------------- 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