简体   繁体   English

从其他SQL表中查找值

[英]Lookup value from other sql table

I have the following sql statement: 我有以下sql语句:

select A.transactionNumber,
A.DealNumber      
A.Group
from TableOne A

inner join TableTwo B     
on A.transactionNumber = B.tranNumber     
where B.ID = 111111  

this yields something like this 这产生这样的事情

transactionnumber  |   DealNumber  |  Group
123                |   1           |   100
456                |   2           |   101

However, there's another table, tableThree, that translates the 'Group' into a string. 但是,还有另一个表tableThree将“ Group”转换为字符串。 It looks like this: 看起来像这样:

Group | GroupLookup
100   | Lookup1
101   | Lookup2
102   | Lookup3

So in summary, I'd like my select to return this: 总而言之,我希望我的选择返回以下内容:

transactionnumber  |   DealNumber  |  Group
123                |   1           |   Lookup1
456                |   2           |   Lookup2

I'm entirely sure that this is simple, however I'm a complete newbie and the presence of the first join in the select is throwing me, I'd very much appreciate any help. 我完全确定这很简单,但是我是一个完全的新手,而选择中首次加入的存在使我感到困惑,我非常感谢您的帮助。

If I correctly understood should be something like: 如果我正确理解应该是这样的:

select A.transactionNumber,
A.DealNumber,     
C.GroupLookup AS [Group]
from TableOne A    
inner join TableTwo B     
on A.transactionNumber = B.tranNumber     
inner join TableThree C
on C.Group = A.Group
where B.ID = 111111  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM