我一直在寻找类似的问题,但无济于事。如果我错过了解决方案,我深表歉意,请指出正确的方向。
我一直在玩 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 子句。设计图看起来完全不同,但任何想法都会非常受欢迎