I have tow tables like
users
id | name
_______________
1 | one
2 | two
3 | three
4 | four
5 | five
6 | six
employees
id | userId | reportedTo
_________________________
1 | 1 | null
2 | 2 | 1
3 | 3 | 2
4 | 4 | 3
5 | 5 | 4
6 | 6 | 5
I need something like
if I run query for some user then it will return all the record which reportedTo is this user and other users which reportedTo is reportedTo this user
Like:
if I run this query for user 1 then it will return all the record accept userId 1 from employees
id | userId | reportedTo
_________________________
2 | 2 | 1
3 | 3 | 2
4 | 4 | 3
5 | 5 | 4
6 | 6 | 5
if I run query for userId 4 then it will return recornds with userId 5 and 6 from employee table
id | userId | reportedTo
_________________________
5 | 5 | 4
6 | 6 | 5
can anyone help me with this.
Thanks in advance