SQL JOIN - WHERE clause vs. ON clause

前端 未结 19 1584
深忆病人
深忆病人 2020-11-21 11:56

After reading it, this is not a duplicate of Explicit vs Implicit SQL Joins. The answer may be related (or even the same) but the question is diffe

19条回答
  •  悲&欢浪女
    2020-11-21 12:49

    For an inner join, WHERE and ON can be used interchangeably. In fact, it's possible to use ON in a correlated subquery. For example:

    update mytable
    set myscore=100
    where exists (
    select 1 from table1
    inner join table2
    on (table2.key = mytable.key)
    inner join table3
    on (table3.key = table2.key and table3.key = table1.key)
    ...
    )
    

    This is (IMHO) utterly confusing to a human, and it's very easy to forget to link table1 to anything (because the "driver" table doesn't have an "on" clause), but it's legal.

提交回复
热议问题