Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Use a Query to Compare Data Among Records


View products that this article applies to.

This article was previously published under Q208890
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).

↑ Back to the top


Summary

This article shows you how you can use a query instead of code to compare data among records.

↑ Back to the top


More information

The following example shows you how to use a query to compare data among the records in the Orders table in the sample database Northwind.mdb. For example, to find orders that were followed by another order within 60 days, follow these steps:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Microsoft Access, and then open the sample database Northwind.mdb.
  2. In the Database window, click Queries under Objects, click Create query in Design view, and then click Design.
  3. In the Show Table dialog box, click the Tables tab, select Orders from the list, and then click Add twice. Click Close.

    NOTE: The second time that you add the table, Access adds it as Orders_1.
  4. Drag CustomerID from the Orders field list to CustomerID in the Orders_1 field list to join the tables in the CustomerID field.
  5. Add the following fields to the query grid:
    Field: CustomerID
    Table: Orders
    Sort: Ascending
    
    Field: OrderDate
    Table: Orders
    Sort: Ascending
    
    Field: DaysBetweenOrders: DateDiff("d",[Orders].[OrderDate],[Orders_1].[OrderDate])
    Criteria: Between 1 And 60
    
    Field: OrderID
    Table: Orders
    
    Field: NextOrderDate: [OrderDate]
    Table: Orders_1
    					
  6. Run the query.
Note that every order followed by another order within 60 days is returned.

↑ Back to the top


References

For more information about queries, click Microsoft Access Help on the Help menu, type queries in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB208890, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 208890
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 260