0

Need a simple mysql query to know the subordinate employee in a organisation. I have created a table which looks as shown below:

emp_code    level    reporting_to
emp001      0        emp001
emp002      1        emp001
emp003      2        emp002
emp004      3        emp001
emp005      3        emp003
emp006      3        emp003
emp007      3        emp001

I need a query using which, I can know the subordinate employees of a given employee, by giving the employee code.

For example, for emp001 all employees will be displayed, for emp002 will list emp003, emp005, emp006 and for emp003 only emp005, emp006 will be displayed.

Thanks in advance.

Pallab DB
  • 3
  • 3
  • If you had shown us an actual query where you were stuck, you could have gotten an answer. But as it stands now, your question is a duplicate. – Tim Biegeleisen Jun 08 '17 at 08:44
  • Hi Tim, the query **select @pv:=reporting_to as category_id, emp_code, level from `user` join (select @pv:='emp002')tmp where reporting_to=@pv** – Pallab DB Jun 08 '17 at 09:01

0 Answers0