1
我找了一個類似的問題無濟於事。如果我錯過了解決方案,我表示歉意,並請指出正確的方向。在T-SQL中,多個INNER JOIN的最佳設計是什麼?
我一直在玩MS AdventureWorks,想知道使用INNER JOIN創建的兩個SELECT語句之間是否有任何功能差異。他們給出了相同的結果。
版本1
SELECT pp.BusinessEntityID, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix,
pe.EmailAddress,
pa.AddressLine1, pa.AddressLine2, pa.City, pa.PostalCode FROM
Person.BusinessEntityAddress AS bea
INNER JOIN Person.Address AS pa
ON bea.AddressID = pa.AddressID
INNER JOIN Person.Person AS pp
ON bea.BusinessEntityID = pp.BusinessEntityID
INNER JOIN Person.EmailAddress AS pe
ON pp.BusinessEntityID = pe.BusinessEntityID
WHERE pp.Suffix IS NOT NULL
2版
SELECT pp.BusinessEntityID, pp.FirstName, pp.MiddleName, pp.LastName, pp.Suffix,
pe.EmailAddress,
pa.AddressLine1, pa.AddressLine2, pa.City, pa.PostalCode
FROM Person.BusinessEntityAddress AS bea
INNER JOIN Person.Address AS pa
ON bea.AddressID = pa.AddressID
INNER JOIN Person.Person AS pp
ON bea.BusinessEntityID = pp.BusinessEntityID
INNER JOIN Person.EmailAddress AS pe
ON bea.BusinessEntityID = pe.BusinessEntityID
WHERE pp.Suffix IS NOT NULL
唯一的區別是在過去的ON子句。雖然 設計圖看起來相當不同