[英]Select Statement pulls values from a junction table into 1 comma delimited string
[英]Select values from 2 tables matching with junction table
我需要使用联结表从表A和表B中选择值。 结果集应具有两个表中的值。 例:
Table A
ID
1
2
3
4
5
Table B
ID
8
9
Junction Table
ID1 ID2
1 8
6 9
如果结点中存在表A或B中的值,则结果应如下所示,那么它应该从结点表中获得1值之一。上例的结果应为
ID
1
2
3
4
5
9
我不遵循逻辑的描述。 但是,根据数据,似乎是A
所有ID以及B
中的ID与junction
A
的ID配对。
如果是这样的话:
select a.id
from a
union all
select b.id
from b
where not exists (select 1
from junction j join
a
on j.id1 = a.id
where j.id2 = b.id
);
这是基于数据的,因此仅查看id2
与b.id
的匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.