Are inner join and cross apply equivalent. Also is Left Outer Join and Outer apply same, then why create this new way?
Loading
Are inner join and cross apply equivalent. Also is Left Outer Join and Outer apply same, then why create this new way?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Jun 18, 2024, 2:12 AM EDT
Hello Dinesh,
Both are completely different and have different usage purposes,
Please find below the details,
When to Use Which?
Uday DodiyaRank #239 · 10.3K reputationPosted Jun 15, 2024, 1:03 AM EDT
Inner Join and Cross Apply, as well as Left Outer Join and Outer Apply, serve different purposes and are not entirely equivalent. Here is a detailed comparison:
Inner Join vs. Cross Apply
Inner Join:
Cross Apply:
Example:
-- Inner Join SELECT a.Column1, b.Column2 FROM TableA a INNER JOIN TableB b ON a.Id = b.AId -- Cross Apply SELECT a.Column1, b.Column2 FROM TableA a CROSS APPLY (SELECT Column2 FROM TableB WHERE TableB.AId = a.Id) bKey Differences:
Left Outer Join vs. Outer Apply
Left Outer Join:
Outer Apply:
Example:
-- Left Outer Join SELECT a.Column1, b.Column2 FROM TableA a LEFT OUTER JOIN TableB b ON a.Id = b.AId -- Outer Apply SELECT a.Column1, b.Column2 FROM TableA a OUTER APPLY (SELECT Column2 FROM TableB WHERE TableB.AId = a.Id) bKey Differences:
Why Use Apply?
Flexibility:
CROSS APPLYandOUTER APPLYprovide the ability to join with derived tables and table-valued functions, offering more flexibility than traditional joins.Dynamic Queries: They allow for dynamic calculations and subqueries that depend on the outer query's row values.
Complex Scenarios: Useful in scenarios where the relationship between tables is not straightforward or static, enabling more complex data retrieval patterns.
Summary
While
INNER JOINandCROSS APPLYcan sometimes produce similar results, they are used in different contexts and are not equivalent. The same applies toLEFT OUTER JOINandOUTER APPLY. TheAPPLYoperators provide additional functionality, especially when working with table-valued functions or complex subqueries, which traditional joins cannot achieve directly.Ishika TiwariRank #298 · 8.4K reputationPosted Jun 15, 2024, 1:07 AM EDT
Naveen KumarRank #249 · 10K reputationPosted Jun 15, 2024, 3:00 AM EDT
No, INNER JOIN and CROSS APPLY are not equivalent. They serve different purposes and are used in different contexts in SQL Server.
INNER JOIN vs CROSS APPLY
INNER JOIN:
SELECT a.*, b.* FROM TableA a INNER JOIN TableB b ON a.Id = b.Id;CROSS APPLY:
SELECT a.*, b.* FROM TableA a CROSS APPLY (SELECT * FROM TableB b WHERE a.Id = b.Id) b;Jaimin ShethiyaRank #177 · 13.7K reputationPosted Jun 15, 2024, 9:41 PM EDT
Hello,
Please refer below difference.
Inner join selects the rows that satisfies both the table.
Cross join selects the all the rows from the first table and all the rows from second table and shows as Cartesian product ie, with all possibilities.
Thanks