Where to use Outer Apply

后端 未结 2 2055
长发绾君心
长发绾君心 2020-12-15 09:36

MASTER TABLE

x------x--------------------x
| Id   |        Name        |
x------x--------------------x
|  1   |          A         |
|  2            


        
2条回答
  •  执念已碎
    2020-12-15 10:07

    In your example queries the results are indeed the same.

    But OUTER APPLY can do more: For each outer row you can produce an arbitrary inner result set. For example you can join the TOP 1 ORDER BY ... row. A LEFT JOIN can't do that.

    The computation of the inner result set can reference outer columns (like your example did).

    OUTER APPLY is strictly more powerful than LEFT JOIN. This is easy to see because each LEFT JOIN can be rewritten to an OUTER APPLY just like you did. It's syntax is more verbose, though.

提交回复
热议问题