Can someone help me in writing Oracle SQL Query for the following scenario:
- Company can have multiple departments.
- Each department can have multiple Employees.
- Employee need not have department assigned but company Id is must.
This is the output I am trying for:
This is the query I have tried So far:
SELECT C.id Company_Id,
C.name Company_Name,
D.id Department_Id,
D.name Department_Name,
E.id Employee_Id,
E.name Employee_Name
FROM Company C
FULL OUTER JOIN Department D
ON D.CompanyId = C.Id
FULL OUTER JOIN Employee E
ON E.CompanyId = C.Id AND E.DepartmentId = D.Id
ORDER BY Company_Id,Department_Id,Employee_Id;
But it gives this output:
EDIT:
Sql fiddle : http://sqlfiddle.com/#!4/df238/3/0