2015-06-02 112 views
0

我是一位具有SQL經驗的分析師,但我還沒有加入超過2個表。我試圖加入這3個表格,但我無法將表格與成功結合在一起。我究竟做錯了什麼?SQL三連接:無法三連接

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無法綁定

+0

你可以發表三張表的表結構嗎?數據庫Db3中的Jobs表上是否有Id列? – TTeeple

+0

您正在使用Persons表兩次加入四張表 – Sherlock

+0

您真的需要在此查詢中的第一個JOIN(Persons to self)嗎? – C8H10N4O2

回答

0

你並不需要PersonJOIN 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 
0

的加入,我不認爲你真的需要先加入以後。 刪除線JOIN ON Persons.Id = Jobs.Id人員和嘗試。你應該很好。