Results 1 to 4 of 4
  1. #1
    XUseMan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    2

    Question Distinct Rows with Max Date

    Dear All,
    I have a table which is mentioned below.
    Branch TxnDate Field1 Field2 Field3
    B1 2/20/2012 1 2 3
    B1 2/23/2012 9 10 11
    B2 2/20/2012 3 4 5
    B2 2/24/2012 12 13 14
    B3 2/20/2012 6 7 8
    B3 2/25/2012 15 16 17

    I need to build a SQL statement which the result should be like below

    Branch TxnDate Field1 Field2 Field3
    B1 2/23/2012 9 10 11
    B2 2/24/2012 12 13 14
    B3 2/25/2012 15 16 17

    The logic of this result is
    1. The Branch name should be unique
    2. TxnDate is the Max(TxnDate) of each branch
    3. Field1, 2, 3 values should be the corresponding values of Max(TxnDate).

    Kindly help me. I have attached the database along with this.
    Attached Files Attached Files

  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,640
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    XUseMan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    Thank you very much for your prompt reply. For those of you who are interested in the solution

    SELECT tbl.*
    FROM tbl INNER JOIN (SELECT Branch, Max(TxnDate) AS MaxOfTxnDate FROM tbl GROUP BY Branch) AS qrytbl
    ON (tbl.Branch=qrytbl.Branch) AND (tbl.TxnDate=qrytbl.MaxOfTxnDate);

  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,640
    Happy to help, and welome to the site by the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 0
    Last Post: 02-09-2012, 05:43 PM
  2. distinct count with criteria and max date
    By TheShabz in forum Queries
    Replies: 3
    Last Post: 09-23-2011, 06:08 AM
  3. Replies: 2
    Last Post: 08-28-2011, 06:06 AM
  4. Replies: 6
    Last Post: 07-21-2011, 04:51 AM
  5. Replies: 1
    Last Post: 06-13-2011, 07:24 AM

Tags for this Thread

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