如何在SQL查询中使用联接? [英] How to use join in sql query?

查看:115
本文介绍了如何在SQL查询中使用联接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft SQL Server,但我想从多个表中使用join.

I am using Microsoft SQL server, and I want to use the join but from multiple tables.

这就是我所拥有的

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匹配,但是出现错误

I want to have the c.FirmID match the e.FirmID, however I get the error

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.

我已注释掉第一个代码块中的三个部分,这会导致错误.有人知道该怎么做吗?

I have commented out the three parts in the first code block, which causes the error. Does anyone know how to do this?

谢谢.

实际上没关系,我不需要这个问题的帮助.

推荐答案

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

The problem is that you are mixing JOIN types, trying using the same JOIN throughout:

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

这篇关于如何在SQL查询中使用联接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆