I have a table EmpList. I want to use loop to bring result as I expected. Example,
EmpNo ReportingTo
-------------------
27 14
68 14
104 27
105 27
138 27
139 68
150 8
151 8
8 5
Suppose query input is 14, I need result like this
EmpNo
------
27
68
104
105
138
139
Here 27,68 reportingto 14 and 104,105,138 reportingto 27 and 139 reportingto 68.
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);
But this query gives only one level result.