We have Employee,Department,Region tables as shown below:
Employee(EmpID, EmpName, Salary)
Department(DeptID, EmpID, DeptName)
Region(RegnID, DeptID, RegnName )
Now get all employee details according to the region (RegnName) they belong?
Solution:
If you want to have all of the employees in the results, despite missing department and region data then you need to use OUTER joins:
Select r.RegnName as 'Region', d.DeptName as 'Dept', e.EmpID as 'Id', e.EmpName as 'Name', e.Salary as Salary FROM Employee LEFT OUTER JOIN Department d ON e.EmpID = d.EmpID LEFT OUTER JOIN Region r ON d.DeptID = r.DeptID ORDER BY r.RegnName, d.DeptName