Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inner join performed after outer join #24

Open
terrajobst opened this issue Oct 31, 2014 · 0 comments
Open

Inner join performed after outer join #24

terrajobst opened this issue Oct 31, 2014 · 0 comments

Comments

@terrajobst
Copy link
Owner

Ported from CodePlex

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant