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

  • 相关阅读:
    【响应式Web设计实践 #BOOK#】
    【JS】(+﹏+)~
    -_-#【邮件】qq邮箱不显示图片
    -_-#【Markdown】
    51Nod——N1284 2 3 5 7的倍数
    51Nod——N1118 机器人走方格
    洛谷——P1014 Cantor表
    洛谷—— P1434 滑雪
    洛谷——P1443 马的遍历
    python(24)- 面向对象进阶
  • 原文地址:https://www.cnblogs.com/watermarks/p/12604925.html
Copyright © 2011-2022 走看看