From: Claudio Nanni Date: March 11 2009 1:33pm Subject: Re: using a subquery/self-join to recursively retrieve a tree List-Archive: http://lists.mysql.com/mysql/216674 Message-Id: <53bcf3a60903110633i14905587hba26ec86f82be962@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=001636c5abdfa288eb0464d7eae6 --001636c5abdfa288eb0464d7eae6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit as you say you need recursion to build the tree from the table. if you are interested just in all the employees that are not manager with their manager info. select * from emp e1 inner join emp e2 on e1.uidman=e2.uid; cheers Claudio 2009/3/10 Ali, Saqib > 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 > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/mysql?unsub=claudio.nanni@stripped > > --001636c5abdfa288eb0464d7eae6--