Given three tables Ta, Tb, Tc:
Ta(ID, Field1)
Tb(ID, Field2)
Tc(ID, Field3)
Given data example:
Ta
ID Field1
---------
1 A
1 B
Tb
ID Field2
---------
1 C
1 D
2 E
Tc
ID Field3
---------
1 F
2 G
2 H
Question:
How can I join this data to return:
ID Field1 Field2 Field3
-----------------------
1 A C F
1 B D NULL
2 NULL E G
2 NULL NULL H
I thought I could achieve this with outer joins but that doesn’t seem to be the case. The order of the groupings doesn’t really matter, as long as I bring back all information without duplicate rows.
Just to clarify. I don’t really mind which combination I get as long as the result set returns all data in the minimum number of rows. Here’s a more realistic example of what I am trying to do:
Given a person, call him John. He has two phone numbers and three email addresses:
PID Email
---------
John john@test.com
John john@mail.com
John john@john.com
PID Tel
--------
John 011
John 022
I want to return:
PID Email Tel
----------------------
John john@test.com 011
John john@mail.com 022
John john@john.com NULL
You can come close with the following:
As I said, though, in my comment, the ordering of rows in a table is not guaranteed, so these may not come out in the order you expect. With your sample data, you could use:
If the fields define the ordering