SQL Join even if there's a mismatch

Viewed 204

I have 3 tables structured like so:

Table A

[ID_A] [name]
1      hello
2      world

Table B

[ID_B] [name]
1      foo
2      bar
3      booboo

Table C

[ID_C] [ID_A] [ID_B]
1      1      1
2      1      2
3      2      2

What i want to have is: for each A.name return a row with 0 or 1 based on the existance of a link between itself and all of the entries in B

Result:

[A.ID] [B.ID] [res]
1      1      1
1      2      1
1      3      0
2      1      0
2      2      1
2      3      0

I tried with normal joins, full outer joins (in my mind they worked perfectly), but i can't manage to do it, because i can't perform a join if there is no row to join on

3 Answers
Related