SQL's CROSS APPLY operator is explained through the analogy of an e-commerce recommendation engine. Unlike a standard JOIN, CROSS APPLY runs a subquery for each individual row — in this case, fetching the top 3 personalized product recommendations per customer ordered by score. A side-by-side comparison with a CTE + ROW_NUMBER() JOIN approach shows that CROSS APPLY produces cleaner, more readable code for per-row logic. Use cases include top-N results per group, dynamic per-row filtering, and calling table-valued functions.
Table of contents
What is actually happening?What do this and CROSS APPLY have in common?How does CROSS-APPLY think?Get Luchiana Dumitrescu’s stories in your inbox781 Impressions