共用方式為


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

另請參閱