问题
I have 2 tables with a 1:1 relation. I'm trying to select everything from table1 and table2 using PK from table1.
I want to select everything from table1 and, IF table1 PK = table2 FK THEN (and, only THEN) select from table2.
To make it short, I want to select from table1 even if the query result doesn't have any relation in table2. If it has, then select from table2 as well.
Anyone know how to do this?
回答1:
It's a left outer join
select table1.*, table2.*
from table1 left outer join table2 on table1.PF = table2.PK
来源:https://stackoverflow.com/questions/21761272/select-from-2-tables-query-table1-or-table1-table2