I have a two tables in SQL Server:
Employee (Parent):
EMPID | EMPNAME | ROLE | DEPTID
1 | John | Manager | M1
2 | George | Employee | E1
3 | Alex | Intern | I1
4 | Bob | Employee | E2
REL (It holds Emp to Emp relationship):
FROM_EID | TO_EID
1 | 2
2 | 3
Expected output:
RELATED_ID
M1-E1-I1
I am using the below query to fetch the details of EMPID 1, 2 and 3 so that I can concat the DEPTIDs later:
select * from REL rel1, REL rel2, REL rel3
where rel1.FROM_EID = rel2.TO_EID
and rel2.FROM_EID = rel3.TO_EID;
But I am not getting the details for EMPID #1 here. How can I achieve this?