I've table name as "Employee" with respective columns(id,employee_id and status). If status is in "pending" and take pending status of "employee_id" and lookup into other records of employee_id column. So employee_id is exist then I've to take id value and store into result_id.
id employee_id status
1 1000 failed
2 1001 failed
3 1002 failed
4 1005 failed
5 1006 failed
6 1005 pending
7 1004 pending
8 1001 pending
9 1002 pending
10 1006 pending
Example : id=6,employee_id=1005 and status='pending' then result_id should be 4 (i.e result_id=4)
Output :
id result_id
1 NULL
2 NULL
3 NULL
4 NULL
5 NULL
6 4
7 NULL
8 2
9 3
10 5
I've tried:
select e.id as id ,e2.id as result_id
from employee as e, employee as e2
where e.employee_id=e2.employee_id and e.id not in (e2.id)
This query will return only value of result_id
but I want Null values too.
Can anybody help me on this?