I am using MySQL. Let’s say I have table A, B and C. Table A is a base table. Table B and C both have foreign keys to table A. However I want to pull out the rows so that the output would look something like this.
A | B | C
----------------
1 | 1 | NULL
1 | 2 | NULL
1 | NULL | 1
1 | NULL | 2
2 | 3 | NULL
2 | NULL | 3
So when B no longer has any rows left for a certain key the query moves on to C and stop outputting rows for B. This seems like it should be simple, but I seem to be having trouble coming up with the way it should be done.
Also the title of the question probably doesn’t make sense, but I wasn’t sure how to best describe the scenario.
Thinking about it, an OUTER JOIN isn’t going to give you the output format you want. Try something like this: