Difference between SQL server apply and join

Source: Internet
Author: User

Cross apply and outer apply are similar to join.

They are mainly engaged in M * n Cartesian sets. The obvious feature is that on joins are not used.

It is also reasonable to think about it. The application scenario should meet the join constraint, mainly for example, the function that returns table variables,

It seems that the difference is still unclear. For example, return the three most recent orders of a customer or return the five most popular products in all categories.

The Top N operation won't work well if we use join. Haha, but it's not impossible to use row_number () partition.

Here, it's easy to use apply. If I don't write it out, I can't remember how to write it after a month.

Another silly way is to traverse all the customers, retrieve the three most recent orders of each user, and insert them to a zero-time table,

This method can also be considered for a small quantity. After all, the method is relatively simple, and you do not need to use the advanced features of SQL Server 2005 +.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.