I have three fields in a table that define a hierarchical relationship present in a MySQL database.
Table Name : tb_corp
--------------------------------------------
comp_code | incharge_comp_Code | mngr_emp_no
A | | 111
--------------------------------------------
B | A |
--------------------------------------------
C | B |
--------------------------------------------
How do I write a query to obtain all the comp_code that mngr_emp_no = 111 is in charge. According to the table above, 111 is in charge of three companies(A, B, and C). The reason is that A company is in charge of B company and B company is in charge of C company as a result A is also in charge of C company. (A -> B) (B -> C) == (A -> C)