UNION
Combines the results of two or more queries into a single collection.
expression
UNION [ ALL ]
expression
Arguments
- expression
Any valid query expression that returns a collection to combine with the collection All expressions must be of the same type or of a common base or derived type as expression.
- UNION
Specifies that multiple collections are to be combined and returned as a single collection.
- ALL
Specifies that multiple collections are to be combined and returned as a single collection, including duplicates. If not specified, duplicates are removed from the result collection.
Return Value
A collection of the same type or of a common base or derived type as expression.
Remarks
UNION is one of the Entity SQL set operators. All Entity SQL set operators are evaluated from left to right. For precedence information for the Entity SQL set operators, see EXCEPT.
Example
The following Entity SQL query uses the UNION ALL operator to combine the results of two queries into a single collection. The query is based on the AdventureWorks Sales Model. To compile and run this query, follow these steps:
Follow the procedure in How to: Execute a Query that Returns StructuralType Results.
Pass the following query as an argument to the
ExecuteStructuralTypeQuery
method:
(SELECT VALUE P from AdventureWorksEntities.Products
as P WHERE P.Name LIKE 'C%') Union All
( SELECT VALUE A from AdventureWorksEntities.Products
as A WHERE A.ListPrice > @price)