I have a MySQL table called EmpList
. I want to use loop to bring result as I expected. For example EmpList having two columns,
EmpNo ReportingTo ------------------- 27 14 68 14 104 27 105 27 138 27 139 68 150 8 151 8 8 5
I am giving EmpNo
as input to the query (ex: 14). I am expecting who are all ReportingTo
EmpNo14
(ex:27,68 from table) and along with it subreportees if any (EmpNo
who are all ReportingTo
27 and 68 (ex:104,105,138 ReportingTo
27 and 139 ReportingTo
68)). Finally I am trying to get result in a single column like
EmpNo ------ 27 68 104 105 138 139
I am trying to get result using query like this
SELECT EmpNo FROM EmpList WHERE ReportingTo IN ( SELECT DISTINCT EmpNo FROM EmpList WHERE ReportingTo = 14 );
This query gives only one level (lowerlevel) result. Input value I am getting dynamically based on login.