1

我正在三个表之间进行连接,虽然这些连接没有组合就可以工作,但当我将它们加在一起时,它会告诉我“'Person' 附近的语法不正确”。

这是我的查询:

SELECT [AddressLine1], [FirstName], [LastName]
FROM
[Person].[BusinessEntityAddress] join [Person].[Address] 
on ([Person].[BusinessEntityAddress].[AddressID]=[Person].[Address].[AddressID])
[Person].[Person] 
join [Person].[BusinessEntityAddress] 
on ([Person].[Person].[BusinessEntityID]=[Person].[BusinessEntityAddress].[BusinessEntityID])
WHERE FirstName= 'Terri' AND LastName= 'Duffy'

问题在最后一行[Person].[Person] join [Person].[BusinessEntityAddress]...

任何帮助将不胜感激。我可以回答问题以使其更具体。

4

1 回答 1

1
SELECT   [Person].[Address].[AddressLine1]
       , [Person].[Person].[FirstName]
       , [Person].[Person].[LastName]
FROM [Person].[BusinessEntityAddress] join [Person].[Address] 
on [Person].[BusinessEntityAddress].[AddressID]=[Person].[Address].[AddressID]
JOIN [Person].[Person] 
ON [Person].[Person].[BusinessEntityID] = [Person].[BusinessEntityAddress].[BusinessEntityID]
WHERE FirstName= 'Terri' AND LastName= 'Duffy'

-- 或者使用 Alias 使其更清晰、更易于阅读

SELECT   PA.[AddressLine1]
       , PP.[FirstName]
       , PP.[LastName]
FROM  [Person].[BusinessEntityAddress] PB 
INNER JOIN 
      [Person].[Address] PA
ON    PB.[AddressID] = PA.[AddressID]
INNER JOIN  
      [Person].[Person] PP
ON    PP.[BusinessEntityID] = PB.[BusinessEntityID]
WHERE PP.[FirstName] = 'Terri' 
AND   PP.[FirstName] = 'Duffy'
于 2014-02-10T20:04:13.680 回答