How to query a table with cardinality one to display all the Pk while also displaying the matching elements in a table with FK
First of all, please forgive me if the question is not clear. I will explain it clearly here.
Ok, lets say, I have a table "TableA" with columns, (ApkColumn, x, y) where ApkColumn is the primary key for TableA and lets say "TableA" has following info:
TableA
ApkColumn|| x || y ||
1 || Bob || Alan
2 || Linda || berry
3 || Andrew || Hall
and
and another table "Table B" with columns, (BpkColumn, M,N, AfkColumn) where BpkColumn is the Primary key for TableB and AfkColumn is the foreign key to Table A.
TableB
BpkColumn||M||N||AfkColumn
1 ||Physics01||Fundamentals of physics|| 1
Now, I want to query A such that I should get results开发者_运维问答 like this:
result table
x||M||N
Bob||Physics01||Fundamentals of physics
Linda||null||null
Andrew|| null||null
i.e. I want to display all the elements from TableA (for a column) and if it have a corresponding column in TableB, it should be displayed else, null should be displayed.
I tried to do a left join against the PK and FK. But, it displays only for the columns in tableB.
Thanks in advance.
It would have been nice to add the query you made cause what you suggested is the way to do it. just make sure that Table A is on the left side of the join:
select .....
from A left outer join B
on (A.ApkColumn=B.AfkColumn)
精彩评论