UniqueRecords Property

Applies To

Query.

Description

You can use the UniqueRecords property to specify whether to return only unique records based on all fields in the underlying data source, not just those fields present in the query itself.

Note The UniqueRecords property applies only to crosstab, data-definition, pass-through, and union queries.

Setting

The UniqueRecords property uses the following settings.

Setting

Description

Yes

(Default) Doesn’t return duplicate records.

No

Returns duplicate records.


You can set the UniqueRecords property in the query property sheet or SQL view of the Query window.

Note You set this property when you create a new query using an SQL statement. The DISTINCTROW predicate corresponds to the UniqueRecords property setting. The DISTINCT predicate corresponds to the UniqueValues property setting.

Remarks

You can use the UniqueRecords property when you want to omit data based on entire duplicate records, not just duplicate fields. Microsoft Access considers a record to be unique as long as the value in one field in the record differs from the value in the same field in another record.

The UniqueRecords property has an effect only when you use more than one table in the query and select fields from the tables used in the query. The UniqueRecords property is ignored if the query includes only one table.

The UniqueRecords and UniqueValues properties are related in that only one of them can be set to Yes at a time. When you set UniqueRecords to Yes, for example, Microsoft Access automatically sets UniqueValues to No. You can, however, set both of them to No. When both properties are set to No, all records are returned.

See Also

ALL, DISTINCT, DISTINCTROW, TOP Predicates (SQL) (Microsoft Office 95 Data Access Reference), UniqueValues Property.

Example

The query in this example returns a list of customers from the Customers table who have at least one order in the Orders table.

Customers Table

Customer name

Customer ID

Bon app’

1

Simons bistro

2

Reggiani Caseifici

3

Queen Cozinha

4


Orders Table

Customer ID

Order ID

1

10

2

11

2

12

4

13

4

14


This SQL statement returns the customer names in the following table.


SELECT DISTINCTROW Customers.[CompanyName] Customers INNER JOIN Orders ON .[CustomerID] = Orders.[CustomerID];

Customers returned

Customer ID

Bon app’

1

Simons bistro

2

Queen Cozinha

4