INTERSECT (Entity SQL)

Returns a collection of any distinct values that are returned by both the query expressions on the left and right sides of the INTERSECT operand. All expressions must be of the same type or of a common base or derived type as expression.

expression INTERSECT expression

Arguments

  • expression
    Any valid query expression that returns a collection to compare with the collection returned from another query expression.

Return Value

A collection of the same type or of a common base or derived type as expression.

Remarks

INTERSECT 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 (Entity SQL).

Example

The following Entity SQL query uses the INTERSECT operator to return a collection of any distinct values that are returned by both the query expressions on the left and right sides of the INTERSECT operand. The query is based on the AdventureWorks Sales Model. To compile and run this query, follow these steps:

  1. Follow the procedure in How to: Execute a Query that Returns StructuralType Results (EntityClient).

  2. Pass the following query as an argument to the ExecuteStructuralTypeQuery method:

(SELECT product from AdventureWorksEntities.Product as product where ....product.ListPrice > 10 ) 
    intersect (select product from AdventureWorksEntities.Product as 
    product where product.ListPrice > 20)

This example produces the following output:

ProductID: 514
Name: LL Mountain Seat Assembly
ProductNumber: SA-M198
MakeFlag: True
ProductID: 515
Name: ML Mountain Seat Assembly
ProductNumber: SA-M237
MakeFlag: True
ProductID: 516
Name: HL Mountain Seat Assembly
ProductNumber: SA-M687
MakeFlag: True
ProductID: 517
Name: LL Road Seat Assembly
ProductNumber: SA-R127
MakeFlag: True
ProductID: 518
Name: ML Road Seat Assembly
ProductNumber: SA-R430
MakeFlag: True
...

See Also

Concepts

Entity SQL Reference

Other Resources

Set Operators