Tuesday, January 2, 2018

When to use CROSS APPLY and OUTER APPLY

CROSS APPLY operator is very similar to CROSS JOIN. For example, the following two queries return the same result sets.
The difference is, the right table expression can represent a different set of rows per each row from the left table. For example, if you want to return most recent order from customer
In addition, in complex queries you can use OFFSET FETCH options.
The problem with this CROSS APPLY, if the right table expression returns empty set then does not return corresponding left rows. If you want to return all the left table rows then you should use OUTER APPLY.
Cheers!
Uma