Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Distinct Clause (Visual Basic)

Restricts the values of the current range variable to eliminate duplicate values in subsequent query clauses.

Distinct

You can use the Distinct clause to return a list of unique items. The Distinct clause causes the query to ignore duplicate query results. The Distinct clause applies to duplicate values for all return fields specified by the Select clause. If no Select clause is specified, the Distinct clause is applied to the range variable for the query identified in the From clause. If the range variable is not an immutable type, the query will only ignore a query result if all members of the type match an existing query result.

The following query expression joins a list of customers and a list of customer orders. The Distinct clause is included to return a list of unique customer names and order dates.

Dim customerOrders = From cust In customers, ord In orders _
                     Where cust.CustomerID = ord.CustomerID _
                     Select cust.CompanyName, ord.OrderDate _
                     Distinct

Community Additions

ADD
Show:
© 2015 Microsoft