title: Recursive query in Mysql
body: <p>Hi i have a table in MySql with 2 columns : empId and mId. empId is the code of an employee and mId the code of his manager. 
  I need to query all the reportees of a manager ie direct and indirect reportee.</p>
  
  <p>I saw some links on google but they don't seem to work. Can somebody help me regarding this.</p>
  
  <p>Example : 
  Sample hierarchy tree looks like</p>
  
  <pre><code>1
   (2       3      )
     (4    5) (6 7)
       (8 9)
  </code></pre>
  
  <p>Hence when queried for 1 the query should return all the nodes in the tree except for 1 and when queries for 2 it should return 4 5 8 9.</p>
  
  <p>Thanks in advance. </p>
  
  <p>EDIT:</p>
  
  <p>This is the link that i tried
  <a href="http://guilhembichot.blogspot.co.uk/2013/11/with-recursive-and-mysql.html" rel="nofollow">http://guilhembichot.blogspot.co.uk/2013/11/with-recursive-and-mysql.html</a>
  This link explains how to create a recursive query but the methods explained over here don't seem to work for me. </p>
  
  <p>@Mike Brant : I check out the link in your comment. But that link was not of much use as i would have to alter the schema of my table to incorporate Nested State Model.And for the first approach i guess i need to know the depth of the tree i am querying for whereas in my problem the depth is unknown. </p>
  
  <p>The schema for my table is:
  create table employees
  { </p>
  
  <pre><code> empId int not null, 
   mId int, 
   primary key (empId)
  </code></pre>
  
  <p>};</p>