【问题标题】:How to use join on three tables如何在三个表上使用连接
【发布时间】:2011-06-09 07:21:40
【问题描述】:

我有三张桌子

表 1 表 2 和表 3。

具有列 ID 的表 1。 表 2 具有列名称 ID、名称。 表三具有列名称 Name。

现在我想从 Table2 中的 table1 中检索 ID,以便与 table 中的 ID 关联的名称应该在 Table3 中。

Table1.ID=Table2.ID(Table2.Name=Table3.Namw)。

不使用 IN 运算符。仅连接。

【问题讨论】:

    标签: oracle


    【解决方案1】:
    select table1.id, table2.name
    from table1
    join table2 on table2.id = table1.id
    join table3 on table3.name = table2.name
    

    【讨论】:

      【解决方案2】:
      select distinct t1.ID
      from Table1 t1
          ,Table2 t2
          ,Table3 t3
      where t1.ID = t2.ID
        and t2.Name = t3.Name
      ;
      

      select t1.ID
      from Table1 t1
      where exists (
        select 1
        from Table2 t2
            ,Table3 t3
        where t1.ID = t2.ID
          and t2.Name = t3.Name
      );
      

      【讨论】:

        猜你喜欢
        • 2015-08-20
        • 1970-01-01
        • 2019-02-05
        • 2018-06-30
        • 2015-10-06
        • 2014-01-01
        • 2018-11-07
        • 2011-04-12
        相关资源
        最近更新 更多