Queries with UNION
When you specify UNION
in a query, SQL Server merges the result sets, applying one of the merge or concatenation operators with sorting strategies to remove any duplicate rows. Figure 34.25 shows an example of an execution plan for the following UNION
query:
SELECT ProductID FROM Sales.SalesOrderDetail sod WHERE sod.OrderQty > 1000UNIONSELECT productID FROM Production.Product p WHERE p.ProductID > 1000
You’ll notice this execution plan is similar to the execution plan for the OR
strategy where the rows are concatenated and then sorted to remove ...
Get Microsoft SQL Server 2014 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.