从2个表中选择。 Query = table1 OR table1 + table2 [英] Select from 2 tables. Query = table1 OR table1 + table2
本文介绍了从2个表中选择。 Query = table1 OR table1 + table2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个表,关系是1:1。
我正在尝试使用来自table1的PK从table1和table2中选择所有内容。
I have 2 tables with a 1:1 relation. I'm trying to select everything from table1 and table2 using PK from table1.
我想从table1中选择所有内容,IF table1 PK = table2 FK那么(并且,只有那么)从table2中选择。
I want to select everything from table1 and, IF table1 PK = table2 FK THEN (and, only THEN) select from table2.
为了简化,我想从table1中选择,即使查询结果在table2中没有任何关系。如果有,则从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.
任何人都知道怎么做?
推荐答案
这是左外连接
select table1.*, table2.*
from table1 left outer join table2 on table1.PF = table2.PK
这篇关于从2个表中选择。 Query = table1 OR table1 + table2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文