Distinct Clause (Visual Basic)

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

Distinct

Remarks

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.

Example

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

See Also

Reference

From Clause (Visual Basic)

Select Clause (Visual Basic)

Where Clause (Visual Basic)

Concepts

Introduction to LINQ in Visual Basic

Other Resources

Queries (Visual Basic)