[英]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.