SQL left join vs multiple tables on FROM line?

前端 未结 11 2567
予麋鹿
予麋鹿 2020-11-22 05:08

Most SQL dialects accept both the following queries:

SELECT a.foo, b.foo
FROM a, b
WHERE a.x = b.x

SELECT a.foo, b.foo
FROM a
LEFT JOIN b ON a.x = b.x
         


        
11条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:41

    When you need an outer join the second syntax is not always required:

    Oracle:

    SELECT a.foo, b.foo
      FROM a, b
     WHERE a.x = b.x(+)
    

    MSSQLServer (although it's been deprecated in 2000 version)/Sybase:

    SELECT a.foo, b.foo
      FROM a, b
     WHERE a.x *= b.x
    

    But returning to your question. I don't know the answer, but it is probably related to the fact that a join is more natural (syntactically, at least) than adding an expression to a where clause when you are doing exactly that: joining.

提交回复
热议问题