SQL Triple Join:无法加入三联

时间:2015-06-02 14:50:40

标签: sql-server join

我是一名具有一定SQL经验的分析师,但我还没有加入超过2个表。我正在尝试加入这3个表,我无法将表绑定在一起并取得成功。我做错了什么?

Use Db3
Select Persons.DateOfBirth
, Persons.DisabilityCode
, Persons.Ethnicity
, Persons.Gender
, Persons.Country
, Persons.MaritalStatus
, Persons.Suffix
, Persons.LastName
, Persons.FirstName
, Persons.MiddleName
, Persons.CommonOrPreferredName
, Persons.Credentials
, Persons.IsActive
, Persons.MilitaryStatus
, Jobs.Id
, Jobs.AdjustedDateOfHire
, Jobs.DateOfHire
, Jobs.CompanyOwnershipStatus
, Jobs.LeaveDate
, Jobs.TerminationDate
, OrganizationalAssociations.Id
, OrganizationalAssociations.EmployeeNumber
, OrganizationalAssociations.SourceSystemEmployeeId
, OrganizationalAssociations.EmploymentType 
From Persons Person

JOIN Persons ON Persons.Id = Jobs.Id
JOIN Jobs ON Jobs.Id = Persons.Id
JOIN OrganizationalAssociations ON OrganizationalAssociations.Id = Persons.Id

错误消息:无法绑定Jobs.Id

2 个答案:

答案 0 :(得分:0)

您不需要使用Person表格JOIN Persons ON Persons.Id = Jobs.Id加入。在使用Person表

删除连接后,您的查询应如下所示
Use Db3
Select Persons.DateOfBirth
, p.DisabilityCode
, p.Ethnicity
, p.Gender
, p.Country
, p.MaritalStatus
, p.Suffix
, p.LastName
, p.FirstName
, p.MiddleName
, p.CommonOrPreferredName
, p.Credentials
, p.IsActive
, p.MilitaryStatus
, j.Id
, j.AdjustedDateOfHire
, j.DateOfHire
, j.CompanyOwnershipStatus
, j.LeaveDate
, j.TerminationDate
, o.Id
, o.EmployeeNumber
, o.SourceSystemEmployeeId
, o.EmploymentType 
From Persons p
JOIN Jobs j ON j.Id = p.Id
JOIN OrganizationalAssociations o ON o.Id = p.Id

答案 1 :(得分:0)

我认为你真的不需要第一次加入.. 删除行JOIN Persons ON Persons.Id = Jobs.Id并尝试。你应该很好。