From: Peter Brawley Date: March 10 2009 10:04pm Subject: Re: using a subquery/self-join to recursively retrieve a tree List-Archive: http://lists.mysql.com/mysql/216663 Message-Id: <49B6E3DF.6040509@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------070307030306010606010109" --------------070307030306010606010109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >How can I do some recursion to get the UIDs of all the employees >reporting up to a manager, regardless of how deep the tree is. I can >do this usindg LDAP and/or PHP, but not sure how to do it as a mysql >query. Examples & discussion at http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html PB ----- Ali, Saqib wrote: > Hello, > > I have following simplistic DB representing a hierarchy: > > +------------+----------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +------------+----------+------+-----+---------+-------+ > | uid | int(10) | NO | PRI | 0 | | > | name | char(80) | YES | | NULL | | > | mail | char(80) | YES | | NULL | | > | manageruid | int(10) | YES | | NULL | | > +------------+----------+------+-----+---------+-------+ > > How can I do some recursion to get the UIDs of all the employees > reporting up to a manager, regardless of how deep the tree is. I can > do this usindg LDAP and/or PHP, but not sure how to do it as a mysql > query. > > Any thoughts? Thanks > > saqib > http://www.capital-punishment.us > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.0.237 / Virus Database: 270.11.9/1993 - Release Date: 03/10/09 07:19:00 > > --------------070307030306010606010109--