Results 1 to 2 of 2
  1. #1
    mor1195 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    1

    One to Many relationship - Match ID with the "many" table and return Max value of specific field

    Hello. I am very new to Access and I am having problems with my query.



    I have one table with customer ID's and their names, and another table with the customer ID's and their orders including dates.
    Many customers have placed more than one order, so in table 2, the ID is repeated.

    -----> I want a query that shows every UNIQUE customer ID in one field, and the other field would be the LATEST date that the customer ordered.

    Can someone help with this? It's pretty urgent.

    Example:
    TABLE 1
    ID NAME
    1 X
    2 Y
    3 Z

    TABLE 2
    ID ORDER ID DATE
    1 56 13-JAN
    1 87 17-JAN
    2 80 15-JAN

    I want a query that results like this:
    ID LATEST ORDER DATE
    1 87 17-JAN
    2 80 15-JAN
    3


    THANKS!!!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Your table structures or names(perhhaps) are a little confusing. Name and Date are reserved words in Access.
    Consider:
    Code:
    TblCustomer 
    CustomerID  pk
    CustNAME  text
    
    with data
    1    John X Doe
    2    Cody Y AckBear
    3    Hesa Z Wynner
    
    tblOrder
    CustomerID  FK Long Integer
    ORDER ID        PK
    OrderDate  DATE 
    
    with data 
    
    1         56                13-JAN
    1         87                17-JAN
    2         80                15-JAN
    
    
    SQL along these lines(untested):
    
    SELECT  CustomerID
    , Max( OrderDate) AS LatestOrderDate
    FROM tblOrder 
    GROUP BY  CustomerID;
    Last edited by orange; 07-09-2015 at 04:14 PM. Reason: added sql

Please reply to this thread with any new information or opinions.

Similar Threads

  1. return "text" when a table field contains 1
    By rafnews in forum Queries
    Replies: 1
    Last Post: 03-26-2015, 02:04 PM
  2. Replies: 1
    Last Post: 02-05-2015, 05:41 PM
  3. Replies: 5
    Last Post: 03-22-2013, 01:11 PM
  4. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  5. Form error "the current field must match..."
    By plavookins in forum Forms
    Replies: 0
    Last Post: 04-13-2011, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums