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 Return Records in a Many-to-Many Relationship


View products that this article applies to.

This article was previously published under Q209193
Novice: Requires knowledge of the user interface on single-user computers.

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

↑ Back to the top


Summary

This article shows you how to design a query to return the records from one table in a many-to-many relationship where each of the records returned is related to two records in the other table in the relationship. Note that the many-to-many relationship between the two tables is broken into two one-to-many relationships with a third (junction) table.

↑ Back to the top


More information

The following steps show you how to create a sample query to return records from one table in a many-to-many relationship:
  1. Open the sample database Northwind.mdb.
  2. Create the following new query based on the Order Detail table:
       Query: Test
       ----------------------
       Type: Select Query
    
       Field Name: OrderID 
          Total: Group By
       Field Name: ProductID 
          Total: Count
          Criteria: >1
       Field Name: ProductID
          Total: Where
          Show: False
          Criteria: 14 or 21
    					
Note that the use of the criteria "14 or 21" with a "Where" total on the ProductID field returns only those order IDs that contain either one or both of the products. The use of the criteria ">1" with a "Count" total on the same field returns only records with both products.

↑ Back to the top


References

For more information about queries, click Microsoft Access Help on the Help menu, type enter criteria in a query or advanced filter to retrieve certain records in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB209193, kbhowto

↑ Back to the top

Article Info
Article ID : 209193
Revision : 4
Created on : 1/26/2005
Published on : 1/26/2005
Exists online : False
Views : 259