• James

    The SQL statement was supposed to do it from the first to the last join. Actually I understand that's the way things worked out in old RDMBSs.

    But SQL SERVER has a powerful Query Optimizer that evaluates the possibilities to choose the best combination of tables so to optimize query performance.

    You can do yourself a simple test to check that. Try running the following queries. This is a simple query (running on ADVENTUREWORKSLT2008) written in two different forms, changing the sequence of the JOINs.

    [font="Courier New"]USE AdventureWorksLT2008

    GO

    SELECT C.CompanyName, P.Name AS Product, SUM(SD.OrderQty) AS OrderQtyTotal

    FROM SALESLT.CUSTOMER C

    INNER JOIN SalesLT.SalesOrderHeader SH ON SH.CustomerID = C.CUSTOMERID

    INNER JOIN SalesLT.SalesOrderDetail SD ON SD.SalesOrderID = SH.SalesOrderID

    INNER JOIN SalesLT.Product P ON P.ProductID = SD.ProductID

    GROUP BY C.CompanyName, P.Name

    GO

    SELECT C.CompanyName, P.Name AS Product, SUM(SD.OrderQty) AS OrderQtyTotal

    FROM SALESLT.Product P

    INNER JOIN SalesLT.SalesOrderDetail SD ON P.ProductID = SD.ProductID

    INNER JOIN SalesLT.SalesOrderHeader SH ON SD.SalesOrderID = SH.SalesOrderID

    INNER JOIN SalesLT.Customer C ON SH.CustomerID = C.CUSTOMERID

    GROUP BY C.CompanyName, P.Name

    GO[/font]

    If you compare the execution plan of each query, you'll see they're exactly the same (due to the work of the QUERY OPTIMIZER).

    (I looked for some reference to show you this idea and only found this pretty short explanation http://bytes.com/topic/sql-server/answers/142445-order-joins-performance)