-
-
Save carinavockell/46e2f1f8aa9f9e1690c370e116393b89 to your computer and use it in GitHub Desktop.
This results in a much more efficient execution plan because the optimizer can use a MERGE JOIN rather than being forced to use an INNER JOIN as with the CROSS APPLY query above.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
soh.SalesOrderID, | |
soh.OrderDate, | |
sub.* | |
FROM Sales.SalesOrderHeader soh | |
JOIN | |
( | |
SELECT | |
sod.SalesOrderID, | |
SUM (sod.UnitPrice) AS UnitPrice, | |
SUM (sod.OrderQty) AS Quantity | |
FROM Sales.SalesOrderDetail sod | |
GROUP BY sod.SalesOrderID | |
) sub | |
ON sub.SalesOrderID = soh.SalesOrderID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment