SELECT ... FROM Customers AS c INNER JOIN (SELECT * FROM Classification WHERE CustomerType = 'Standard') AS cf ON c.TypeCode = cf.Code INNER JOIN SalesReps s ON cf.SalesRepID = s.SalesRepID SELECT ... FROM Customers AS c INNER JOIN Classification AS cf ON c.TypeCode = cf.Code INNER JOIN SalesReps AS s ON cf.SalesRepID = s.SalesRepID WHERE cf.CustomerType = 'Standard'
SQL Server will process both queries the same.
These queries are identical in performance. You can freely exchange ON , WHERE and viewing conditions in a row: SQL Server Optimizer is smart enough to determine the best plan.
The first request is more easily converted to OUTER JOIN whenever the need arises, however in this case it can be better formulated as follows:
SELECT ... FROM Customers AS c INNER JOIN -- or OUTER JOIN Classification AS cf ON cf.Code = c.TypeCode AND cf.CustomerType = 'Standard' INNER JOIN -- or OUTER JOIN SalesReps AS s ON s.SalesRepID = cf.SalesRepID
When writing queries, I try to write them down so that the key character is obvious from the query.
If there is one column in cf.code , I would use the following:
SELECT ... FROM Customers AS c INNER JOIN Classification AS cf ON cf.Code = c.TypeCode INNER JOIN SalesReps AS s ON s.SalesRepID = cf.SalesRepID WHERE cf.CustomerType = 'Standard'
If the key is cf (Code, CustomerType) , then this one:
SELECT ... FROM Customers AS c INNER JOIN Classification AS cf ON cf.Code = c.TypeCode AND cf.CustomerType = 'Standard' INNER JOIN SalesReps AS s ON s.SalesRepID = cf.SalesRepID
and if the key is cf (CustomerType, Code) , then this one:
SELECT ... FROM Customers AS c INNER JOIN ( SELECT * FROM Classification WHERE CustomerType = 'Standard' ) AS cf ON cf.Code = c.TypeCode INNER JOIN SalesReps s ON s.SalesRepId = cf.SalesRepID
A quick note: in MySQL inline views are much less efficient than joins, so I won’t use them in MySQL in this case.
This does not apply to SQL Server .