【问题标题】:Add condition while using LEFT OUTER JOIN使用 LEFT OUTER JOIN 时添加条件
【发布时间】:2011-11-01 03:41:57
【问题描述】:

我有两个表我想在使用 LEFT OUTER JOIN 时添加一个条件

select tt.description,tt.visible,vct.currvalue 
from tblemployee tt 
left outer join viwcurrentemployee vct on vct.transitiontype = tt.cid
                                      and vct.employee = 63 
                                      and tt.visible = 1 
order by tt.cid

我只想要那些可见 = 1 为真但查询忽略条件的记录,而且我必须使用左外连接的一件事因为我想要左表中的记录甚至右表中不存在的记录如何检查条件是我只会从左表中获取可见为 1 的记录

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    试试这个

    select tt.description,
           tt.visible,
           vct.currvalue 
    from tblemployee tt 
      left outer join viwcurrentemployee vct 
        on vct.transitiontype = tt.cid and 
           vct.employee = 63
    where tt.visible = 1 
    order by tt.cid
    

    我将 tt.visible = 1 移动到 where 子句。 vct.employee = 63 需要留在联接中,否则您将没有外部联接。

    【讨论】:

      【解决方案2】:
      select tt.description,tt.visible,vct.currvalue 
      from tblemployee tt 
      left outer join viwcurrentemployee vct on vct.transitiontype = tt.cid
                                            and vct.employee = 63 
      where tt.visible = 1 
      order by tt.cid
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-02-23
        • 1970-01-01
        • 2014-08-10
        • 2013-03-10
        • 1970-01-01
        • 2022-09-29
        • 2010-09-29
        相关资源
        最近更新 更多