Note: I got similar problems but without where condition.
I want to get all user ids who are reporting to a particular user id.(Directly reporting and indirect reporting)
Egs:
If I input user_id = 1, I want to get user_ids 2,3,4,5. ie
2 is reporting to 1,
3 is reporting to 2,
4 is reporting to 3,
5 is reporting to 4.
Here I am adding the SQL Fiddle
Note: Prefering a solution without stored procedure or functions
Thanks.