[英]getting data in oracle from 2 tables where no entries are guanranteed in one or both tables
我将简化我现有的示例。 可以说我有
table1: with ID1, Car; ID2, Bus
并且
table2: with ID1, red; ID3, green
现在我想获取ID1
所有内容,这很简单:
select * from table1, table2 WHERE table1.ID = table2.ID AND table1.ID = 1
我得到ID1, Car, red
。
但如果我要求ID = 2
由于ID2
在table2
缺少条目,我什么也没得到。 但是我想要ID2
(以及 ID3)的所有数据,即使它只有 1 个表中的数据。
我尝试了一个FULL JOIN
这给了我
ID2, Bus
但是,当我尝试在C#
阅读这些内容时,即使在Toad
for Oracle
获得答案时,我也得到the datareader has no rows
。
你似乎想要一个left join
:
select *
from table1 t1
left join table2 t2 on t1.ID = t2.ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.