![]() |
Difference Between "Unique Values" (SELECT DISTINCT) and "Unique Records" (SELECT DISTINCTROW) in Microsoft Access QueriesProvided by: Molly Pell, Technical Project ManagerIntroductionIn Microsoft Access, the SQL syntax of your query may say "Select Distinct" or "Select DistinctRow". Are you familiar with the difference? Learn how this impacts which records and number of records you see, and whether they can be edited. Unique Values and Unique Records PropertiesWhen creating a query in Microsoft Access, you might want to return only distinct or unique values. There are two options in the query's property sheet, "Unique Values" and "Unique Records":
These properties correspond with the DISTINCT and DISTINCTROW statements (respectively) in SQL. DISTINCT versus DISTINCTROW SQL KeywordsDISTINCT and DISTINCTROW sometimes provide the same results, but there are significant differences: DISTINCTDISTINCT checks only the fields listed in the SQL string and then
eliminates the duplicate rows. Results of DISTINCT queries are not
updateable. They are a snapshot of the data. DISTINCTROWDISTINCTROW, on the other hand, checks all fields in the table that is being queried, and eliminates duplicates based on the entire record (not just the selected fields). Results of DISTINCTROW queries are updateable. ExampleAssume you have a simple orders database with the following data:
You can see that ABC in London has 2 orders (CustID = 1), ABC in Paris has 1 order, and Acme has 1 order. SELECT Query
SELECT DISTINCT Query (Unique Values property = Yes)
SELECT DISTINCTROW Query (Unique Records property = Yes)
Here, you see both ABC, Inc. companies (the one in London and the one in Paris), even though the output fields match. The query results are updateable because they correspond to the individual records in the Customers table. SummarySo to summarize, use DISTINCT if you need a snapshot of certain data, without seeing duplicates in the results. Use DISTINCTROW if you want to return entirely distinct records, regardless of what’s shown by the output. To discuss this further, visit our blog.
Note that Microsoft SQL Server supports DISTINCT, but not DISTINCTROW.
If you plan to migrate to SQL Server, do not rely on DISTINCTROW queries. Additional Resources |
Related Products:For data analysis beyond the power of Microsoft Access queries: Database documentation and analysis including object cross-reference, performance optimization, and finding unused queries: Well written and tested modules and classes that you can use royalty-free: Tools to standardize and enhance your module code, including an ADO and DAO Recordset Builder: Send personalized emails with your Access data and reports: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Contact Us
l Web questions: Webmaster
l Copyright
© 2010 FMS, Inc., Vienna, Virginia |