Select from 2 tables. Query = table1 OR table1 + table2

痞子三分冷 提交于 2020-01-06 04:04:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!