繁体   English   中英

从 2 个表中获取 oracle 中的数据,其中一个或两个表中没有任何条目

[英]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

由于ID2table2缺少条目,我什么也没得到。 但是我想要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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM