-1

我正在使用 Microsoft SQL 服务器,我想使用join但来自多个表。

这就是我所拥有的

select a.*, b.Position_Name, c.StartDate, c.EndDate--, e.firmName
from NewHire a--, Firms e
join Position b on a.Position_ID = b.Position_ID
join WorkPeriod c on a.HireID = c.HireID-- and c.FirmID = e.FirmID
where a.Archived = 0 
order by a.HireID desc

我想让 c.FirmID 与 e.FirmID 匹配,但是我得到了错误

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "a.Position_ID" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "a.HireID" could not be bound.

我已经注释掉了导致错误的第一个代码块中的三个部分。有谁知道如何做到这一点?

谢谢。

编辑:其实没关系,我不需要这个问题的帮助。

4

1 回答 1

3

问题是您正在混合 JOIN 类型,并尝试在整个过程中使用相同的 JOIN:

select a.*, b.Position_Name, c.StartDate, c.EndDate, e.firmName
from NewHire a
join Position b 
    on a.Position_ID = b.Position_ID
join WorkPeriod c 
    on a.HireID = c.HireID
join Firms e
    on c.FirmID = e.FirmID
where a.Archived = 0 
order by a.HireID desc
于 2013-05-13T16:09:11.750 回答