UniqueValues Property

Applies To

Query.

Description

You can use the UniqueValues property when you want to omit records that contain duplicate data in the fields displayed in Datasheet view. For example, if a query’s output includes more than one field, the combination of values from all fields must be unique for a given record to be included in the results.

Note The UniqueValues property applies only to all queries except append, make-table, and select queries.

Setting

The UniqueValues property uses the following settings.

Setting

Description

Yes

Displays only the records in which the values of all fields displayed in Datasheet view are unique.

No

(Default) Displays all records.


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

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

Remarks

When you set the UniqueValues property to Yes, the results of the query aren’t updatable and won’t reflect subsequent changes made by other users.

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

Tip If you want to count the number of instances of a value in a field, create a totals query.

See Also

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

Example

The SELECT statement in this example returns a list of the countries in which there are customers. Because there may be many customers in each country, many records could have the same country in the Customers table. However, each country is represented only once in the query results.

This example uses the Customers table, which contains the following data.

Country

Company name

Brazil

Familia Arquibaldo

Brazil

Gourmet Lanchonetes

Brazil

Hanari Carnes

France

Du monde entier

France

Folies gourmandes

Ireland

Hungry Owl All-Night Grocers

Germany

Frankenversand


This SQL statement returns the countries in the following table.


SELECT DISTINCT Customers.[Country]Customers;

Countries returned

Brazil

France

Ireland

Germany