zoukankan      html  css  js  c++  java
  • SQL外连接与条件 left outer join + WHERE/AND 区别

    ref:https://www.cnblogs.com/cy163/archive/2008/10/16/1312920.html

    2.3.4        外连接与条件配合使用
    当在内连接查询中加入条件是,无论是将它加入到join子句,还是加入到where子句,其效果是完全一样的,但对于外连接情况就不同了。当把条件加入到 join子句时,SQL Server、Informix会返回外连接表的全部行,然后使用指定的条件返回第二个表的行。如果将条件放到where子句中,SQL Server将会首先进行连接操作,然后使用where子句对连接后的行进行筛选。下面的两个查询展示了条件放置位子对执行结果的影响:
    条件在join子句
    select *
    from  t_institution i
    left outer join t_teller t
    on i.inst_no = t.inst_no
    and i.inst_no = “5801”
    结果是:
    inst_no    inst_name            inst_no    teller_no  teller_name
    5801       天河区               5801       0001       tom
    5801       天河区               5801       0002       david
    5802       越秀区
    5803       白云区
    条件在where子句
    select *
    from  t_institution i
    left outer join t_teller t
    on i.inst_no = t.inst_no
    where i.inst_no = “5801”
    结果是:
    inst_no    inst_name            inst_no    teller_no  teller_name
    5801       天河区               5801       0001       tom
    5801       天河区               5801       0002       david

  • 相关阅读:
    插入迭代器
    operator[] 和 insert
    STL注意比较函数
    remove、erase
    reserve的使用
    allocator
    【转】【模板】求割点和桥
    【模拟,时针分针秒针两两夹角】【没有跳坑好兴奋】hdu
    【强连通分量分解】
    【模拟ACM排名】ZOJ-2593 Ranking (Andrew Stankevich’s Contest #5)
  • 原文地址:https://www.cnblogs.com/watermarks/p/12604925.html
Copyright © 2011-2022 走看看