Distinct 子句 (Visual Basic)

限制目前範圍變數的值,以消除後續查詢子句中的重複值。

語法

Distinct  

備註

您可以使用 Distinct 子句來傳回唯一項目的清單。 Distinct 子句會使查詢忽略重複的查詢結果。 Distinct 子句會套用至 Select 子句所指定之所有傳回欄位的重複值。 如果未指定 Select 子句,則 Distinct 子句會套用至 From 子句中所識別之查詢的範圍變數。 如果範圍變數不是不可變的類型,只有在類型的所有成員都符合現有的查詢結果時,查詢才會忽略查詢結果。

範例

下列查詢運算式會聯結客戶清單和客戶訂單清單。 包含了 Distinct 子句來傳回唯一客戶名稱和訂單日期的清單。

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

另請參閱