Filtering using the JOIN instead of WHERE

前端 未结 6 1085
别那么骄傲
别那么骄傲 2021-01-11 16:49

In SQL (MSSQL, Oracle, etc., whatever), when joining tables, what is the gain from adding a filter to the JOIN statement instead of having it in the WHERE clause?

i.

6条回答
  •  清酒与你
    2021-01-11 17:13

    These syntaxes are synonymous and are optimized to the same thing by most RDBMS.

    I usually prefer this syntax:

    SELECT  *
    FROM    X
    INNER JOIN
            Y
    ON      X.A = Y.A
    WHERE   X.B = 'SOMETHING'
    

    when B is not a part of the logical link between A and B, and this one:

    SELECT  *
    FROM    X
    INNER JOIN
            Y
    ON      X.A = Y.A
            AND X.B = 'SOMETHING'
    

    when it is.

提交回复
热议问题