具有内部联接的唯一字段 [英] Unique field with inner join
问题描述
我有两个表(table1和table2):
Table1:
fld_1(PK)
fld_2
fld_3
表2:
fld_a(PK)
fld_b
fld_c
Table1.fld_1和Table2.fld_b相关.
我该怎么办want是一个列表,该列表选择Table1中与Table2相关的唯一行.
所以:
Table1:
1 吉姆 琼斯
2 杰夫 < Hill
3 托尼詹姆斯
表2:
1 1 鲍勃
2 1 米莉
3 1 蒂莉
4 2 乔
5 2 吉利
6 3 弗兰克
所以吉姆应该和鲍勃,米莉和蒂莉有关.杰夫:乔和吉莉.还有Tony:Frank.
内部联接返回Jim和Geof的多条记录,因为有许多与它们相关的记录,而我只希望它们出现一次.
有什么建议吗? :(
DISTINCT是我想要的关键字.
但是我也需要它来显示Jim和Jones ...区别只显示一个字段...
>
Hi,
I have two tables (table1 and table2):
Table1:
fld_1 (PK)
fld_2
fld_3
Table2:
fld_a (PK)
fld_b
fld_c
Table1.fld_1 and Table2.fld_b are related.
What I want is a list which selects unique rows in Table1 which related to Table2.
So:
Table1:
1 Jim Jones
2 Geoff Hill
3 Tony James
Table2:
1 1 Bob
2 1 Milly
3 1 Tilly
4 2 Joe
5 2 Jilly
6 3 Frank
So Jim should related to: Bob, Milly and Tilly. Geoff: Joe and Jilly. And Tony: Frank.
An inner join returns multiple records of Jim and Geof as there are multiple records relating to them, where as I only want them to appear once.
Any suggestions? :(
DISTINCT is the keyword you want, I believe.
But I also need it to show Jim and Jones... distinct will only display one field...
这篇关于具有内部联接的唯一字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!