【问题标题】:How to use join in sql query? [closed]如何在sql查询中使用join? [关闭]
【发布时间】:2013-05-13 16:06:14
【问题描述】:

我正在使用 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.

我已经注释掉了第一个代码块中的三个部分,这会导致错误。有谁知道怎么做?

谢谢。

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

【问题讨论】:

    标签: sql sql-server join


    【解决方案1】:

    问题在于您正在混合 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多