I have a 2 tables with a many-2-many relationship:
tableA (ida, valA)
tableB (idb, valB)
tableAB (ida, idb)
I need one query that should return in every tupple:
(ida, idb, 0/1 if related or not)
Here is some input / output example: tableA
ida valA
1 b
2 s
3 l
<强 > 表格B 强>
idb valB
11 aaa
22 bbb
33 ccc
<强度表AB 强度>
ida idb
1 11
2 33
预期成果:
ida idb is_exists
1 11 1
2 11 0
1 33 0
2 33 1
Note that I don t need permutations which are always 0, for example ida=3 or idb=22
this is because it means that in a matrix the whole row or column is 0 (this shows that the row has no relation whatsoever with the other table)
ida | | |
idb | 1 | 2 | 3
---------------------------
11 | 1 | 0 | 0
---------------------------
22 | 0 | 0 | 0
---------------------------
33 | 0 | 1 | 0