This project has moved and is read-only. For the latest updates, please go here.
1

Closed

Inner join performed after outer join

description

SELECT  EmpWithTerrs.FirstName,
        EmpWithTerrs.LastName,
        EmpWithTerrs.TerritoryDescription,
        Regs.RegionDescription
FROM    (
            SELECT  e.firstname,
                    e.lastname,
                    t.*
            FROM    Employees e
                        INNER JOIN EmployeeTerritories et ON et.EmployeeID = e.EmployeeID
                        RIGHT JOIN Territories t ON t.TerritoryID = et.TerritoryID
        ) AS EmpWithTerrs
        INNER JOIN
        (
            SELECT  *
            FROM    Region r
        ) AS Regs ON Regs.RegionId = EmpWithTerrs.RegionId
WHERE   EmpWithTerrs.FirstName = 'Robert'
OR      EmpWithTerrs.FirstName IS NULL
ORDER BY 2, 1
The inner join between regions and territories should be performed before the outer join.
Closed Oct 31, 2014 at 7:32 AM by terrajobst

comments