Results 1 to 5 of 5
  1. #1
    siema24 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    22

    Find the oldest date using a query

    Hi, I'm wondering how to create a query that will filter data from a table based on the oldest date of apperance.
    For example: I have a table tblCustomerDateComment there I put comments (many per one customer) to customers.


    It consists of 3 fields:
    - customerID (type: number)
    - comment (type: text)
    - date (type: date)

    If it is filled with following data:

    1, 'create a customer', 2014
    1, 'customer stops to pay!', 2015
    1, 'delete customer', 2016
    2, 'create a customer', 1990
    2, 'contact details updated', 1991

    then I want my query to returns exact two rows (rows count = customers count):
    1, 'create a customer', 2014
    2, 'create a customer', 1990

    do you guys know what statement should i put into "date" field criteria within a query to do it? thanks in advance!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Since you want the comment associated with the date, this type of thing is one way:

    http://www.baldyweb.com/LastValue.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I see Paul has answered.
    Here is another
    Code:
    SELECT *
    FROM Custcomments
    WHERE commentdate IN (
            SELECT Min(Custcomments.CommentDate)
            FROM Custcomments
            GROUP BY Custcomments.CustId
            )

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by orange View Post
    I see Paul has answered.
    Here is another
    Code:
    SELECT *
    FROM Custcomments
    WHERE commentdate IN (
            SELECT Min(Custcomments.CommentDate)
            FROM Custcomments
            GROUP BY Custcomments.CustId
            )

    I can't see how that would work with real data. Given expanded sample data, wouldn't it pull all comments with a 2014 or 1990 date?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

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

Similar Threads

  1. Displaying Oldest and Newest Date in Query
    By spyldbrat in forum Access
    Replies: 2
    Last Post: 07-28-2015, 12:56 PM
  2. find oldest letter in table
    By megatronixs in forum Queries
    Replies: 7
    Last Post: 07-13-2015, 11:49 AM
  3. Replies: 2
    Last Post: 09-16-2014, 02:25 PM
  4. Replies: 2
    Last Post: 12-08-2012, 10:01 AM
  5. Replies: 3
    Last Post: 05-03-2011, 01:36 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