zoukankan      html  css  js  c++  java
  • SQL JOIN

    SQL JOIN - WHERE clause vs. ON clause

    回答1

    They are not the same thing.

    Consider these queries:

    SELECT *
    FROM Orders
    LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID
    WHERE Orders.ID = 12345
    

    and

    SELECT *
    FROM Orders
    LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID 
        AND Orders.ID = 12345
    

    The first will return an order and its lines, if any, for order number 12345. The second will return all orders, but only order 12345 will have any lines associated with it.

    With an INNER JOIN, the clauses are effectively equivalent. However, just because they are functionally the same, in that they produce the same results, does not mean the two kinds of clauses have the same semantic meaning.

    回答2

    outer join的时候,比如left outer join, 会以左表为主

    • Does not matter for inner joins

    • Matters for outer joins

      a. WHERE clause: After joining. Records will be filtered after join has taken place.

      b. ON clause - Before joining. Records (from right table) will be filtered before joining. This may end up as null in the result (since OUTER join).

  • 相关阅读:
    垃圾回收机制,正则模块
    日常模块
    文件路径带有字符串的处理方法
    QT进制之间的相互转换
    4-7 selectors模块
    4-5 异步IO模型
    4-4 多路复用IO模型
    4-3 非阻塞IO
    4-2 阻塞IO
    4-1 IO模型介绍
  • 原文地址:https://www.cnblogs.com/chucklu/p/14611633.html
Copyright © 2011-2022 走看看