内在2表上有多个连接值 [英] Inner on on 2 table having multiple join value
本文介绍了内在2表上有多个连接值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have following tables.Here I have mentioned few cols of tables.
Table 1:
Id RefId PhoneNumber
1 11 919191
2 11 888888
3 11 919191
Table 2:
Id RefId City UniqueId
1 11 Mumbai 111
2 11 Pune 222
3 11 Nashik 333
I wants few cols from Table1 and Table2.Common in both table is RefId.Table 2 has UniqueId which is primary key of Table2. If I do inner join base on refId,will get 9 record.But I want 3,how to fetch that?
我尝试了什么:
选择T1.PhoneNumber,T2.City,T2.UniqueId,T2.RefId
来自表1 T1
内部加入表2 T2
on T1.RefId = T2.RefId
What I have tried:
select T1.PhoneNumber,T2.City,T2.UniqueId,T2.RefId
From Table1 T1
Inner Join Table2 T2
on T1.RefId = T2.RefId
推荐答案
如果有任何重复的值,你不想只使用不同的。
例如,如果有重复的电话号码:
if there are any duplicated values that you don't want just use the distinct.
example if there are duplicates phone numbers make:
select distinct (T1.PhoneNumber) ,T2.City,T2.UniqueId,T2.RefId
From Table1 T1
Inner Join Table2 T2
on T1.RefId = T2.RefId
这篇关于内在2表上有多个连接值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文