LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

后端 未结 12 1879
失恋的感觉
失恋的感觉 2020-11-21 13:25

What is the difference between LEFT JOIN and LEFT OUTER JOIN?

12条回答
  •  温柔的废话
    2020-11-21 13:43

    Just in the context of this question, I want to post the 2 'APPLY' operators as well:

    JOINS:

    1. INNER JOIN = JOIN

    2. OUTER JOIN

      • LEFT OUTER JOIN = LEFT JOIN

      • RIGHT OUTER JOIN = RIGHT JOIN

      • FULL OUTER JOIN = FULL JOIN

    3. CROSS JOIN

    SELF-JOIN: This is not exactly a separate type of join. This is basically joining a table to itself using one of the above joins. But I felt it is worth mentioning in the context JOIN discussions as you will hear this term from many in the SQL Developer community.

    APPLY:

    1. CROSS APPLY -- Similar to INNER JOIN (But has added advantage of being able to compute something in the Right table for each row of the Left table and would return only the matching rows)
    2. OUTER APPLY -- Similar to LEFT OUTER JOIN (But has added advantage of being able to compute something in the Right table for each row of the Left table and would return all the rows from the Left table irrespective of a match on the Right table)

    https://www.mssqltips.com/sqlservertip/1958/sql-server-cross-apply-and-outer-apply/

    https://sqlhints.com/2016/10/23/outer-apply-in-sql-server/

    Real life example, when to use OUTER / CROSS APPLY in SQL

    I find APPLY operator very beneficial as they give better performance than having to do the same computation in a subquery. They are also replacement of many Analytical functions in older versions of SQL Server. That is why I believe that after being comfortable with JOINS, one SQL developer should try to learn the APPLY operators next.

提交回复
热议问题