Results 1 to 6 of 6
  1. #1
    JRCharlie's Avatar
    JRCharlie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    20

    how to display the last order date

    Hi all I have a customer table with an address Column and an Order table with a OrderDate column .
    I would like to create a Query that would display the customer address and only the Last order made.
    So far I was only able to display the address and and all the Order dates

  2. #2
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    how to display the last order date

    Use SELECT TOP 1 from the Orders Table then join the Customers to that.

  3. #3
    JRCharlie's Avatar
    JRCharlie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    20
    Thanks Alex for your reply.
    I have tried it many ways but can't come up with the right query.
    This is one of my tries, it returns one date and one customer only, and this date is not the earliest . Could you help me with it.

    SELECT TOP 1 Orders.OrderDate, Customer_Tbl.ID
    FROM Customer_Tbl RIGHT JOIN Orders ON Customer_Tbl.ID = Orders.CustomerID;

  4. #4
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    how to display the last order date

    You would need to order the query to get the last one or an example

    SELECT ID, MAX(DATE)
    FROM [table]
    GROUP BY ID

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If you want to retrieve all related data, not just the ID and Max Date, a subquery is one method:

    http://allenbrowne.com/subquery-01.html#TopN

    Another is DMax domain aggregate function:

    SELECT * FROM Orders WHERE [OrderDate]=DMax("[OrderDate]", "Orders", "ID=" & [ID]);
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    JRCharlie's Avatar
    JRCharlie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    20
    Thanks You Both for your replies I have it working

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

Similar Threads

  1. display order number
    By Hopeless in forum Forms
    Replies: 3
    Last Post: 08-25-2012, 06:46 PM
  2. Replies: 7
    Last Post: 10-03-2011, 12:44 PM
  3. Have query Display Days in Order
    By jo15765 in forum Queries
    Replies: 3
    Last Post: 09-27-2011, 08:59 AM
  4. Combobox display order
    By Duncan in forum Queries
    Replies: 91
    Last Post: 09-01-2011, 05:12 PM
  5. Combobox form display order
    By Duncan in forum Access
    Replies: 5
    Last Post: 08-23-2011, 05:17 PM

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