【问题标题】:getting data in oracle from 2 tables where no entries are guanranteed in one or both tables从 2 个表中获取 oracle 中的数据,其中一个或两个表中不保证有条目
【发布时间】:2020-10-05 14:55:16
【问题描述】:

我将简化我现有的示例。 假设我有

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

由于table2 中缺少ID2 的条目,我什么也得不到。 但我想要ID2(以及 ID3)的所有数据,即使它只有 1 个表中的数据。

我尝试了FULL JOIN,它给了我

ID2, Bus

但是当我尝试在C# 中阅读这些内容时,我得到了the datareader has no rows,即使在Toad 中获得Oracle 的答案。

【问题讨论】:

标签: c# oracle join


【解决方案1】:

你似乎想要一个left join

select *
from table1 t1 
left join table2 t2 on t1.ID = t2.ID

【讨论】:

  • 我认为你需要一个完整的外部联接。请参阅我上面的评论以获取可视化效果
猜你喜欢
  • 1970-01-01
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多