【问题标题】:How to join the 8 table in oracle?oracle如何加入8张表?
【发布时间】:2011-01-13 08:52:14
【问题描述】:

您好,我有近 8 个表需要加入并获得完整结果。请对此提供任何帮助。我怀疑我们可以使用而不是加入。

【问题讨论】:

  • 近 8 张桌子?所以......像七张桌子?还是七张桌子和一个视图?
  • 你为什么怀疑它是可能的?

标签: sql oracle11g


【解决方案1】:

如果你有 8 个表名为:

a having id and data1 attributes.
b having id and data2 attributes.
c having id and data3 attributes.
d having id and data4 attributes.
e having id and data5 attributes.
f having id and data6 attributes.
g having id and data7 attributes.
h having id and data8 attributes.

那么,如果要显示所有表的数据:

sql>select a.data1,b.data2,c.data3,d.data4,e.data5,f.data6,g.data7,h.data8 from a,b,c,d,e,f,g,h where a.id=b.id and b.id=c.id and c.id=d.id and d.id=e.id and e.id=f.id and f.id=g.id and g.id=h.id;

【讨论】:

    【解决方案2】:

    可以加入八个表,SQL 规范中没有禁止它,如果一个像样的 DBMS 被限制在那个级别,我会感到非常惊讶。是的,尽管它无法区分空字符串和 NULL,但许多确实认为 Oracle 不错:-)

    但是,我建议您在此处发布您的架构和您需要哪些列,以便我们可以从更高的层次帮助您。

    即使在企业数据库中,也很少会看到这样的复杂连接。这样的查询也有可能出现性能问题。

    【讨论】:

    • 我认为 Oracle 不错因为它消除了试图在空和 NULL 之间做出不自然的区分。 ;-)
    • 哦,@Thilo,我如此很想开始一场关于区分已知空白和未知的宗教战争,但我会避免:- ) 主要是因为 winkie。
    【解决方案3】:

    连接这么多表是很有可能的,但很难阅读。 最好为子查询创建多个视图并加入这些视图,或者在主查询中使用子查询并简单地使用它。 SQL 当然会变得相当长,但可能更容易阅读。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 2018-07-21
      • 2015-05-12
      相关资源
      最近更新 更多