Results 1 to 4 of 4
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    How do i compare rows within the same table & the criteria is to get data by the latest date

    Can anyone help me with this ?

    I would like to compare the date with the SAME ID and extract the row based on LV_DATE - the latest date .

    Is it possible to do so ?
    I tried to do it in query but I couldn't get the result that I want : Below is the code

    Code:
    SELECT a.GROUP_NO , iif( a.LV_DATE < b.LV_DATE , b.LV_DATE , a.LV_DATE ) AS LVDate , b.LV_INS
    FROM test4 AS A 
    INNER JOIN test4 AS B 
    ON (A.LV_INS < B.LV_INS) AND (a.GROUP_NO = b.GROUP_NO)
    WHERE ((A.LV_INS) <> (B.LV_INS))  ;

    Kindly help Thanks in advance


    This is the result that I want based on the table below

    GROUP_NO LVDATE LV_INS
    1 01/01/2016 ABC
    2 02/02/2016 RED
    3 02/02/2016 JIN






    Here is the sample of my table

    GROUP_NO LVDATE LV_INS
    1 01/01/2015 ABC
    1 01/01/2016 ABC
    2 02/02/2016 RED
    2
    3 02/02/2016 JIN
    3 02/02/2016 JIN


  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    two solutions

    Code:
    SELECT *
    FROM test4 as A
    WHERE A.LVDate=(SELECT Max(LVDate) FROM test4 WHERE GroupNo=A.GroupNo)
    and (probably faster for large datasets)

    Code:
    SELECT A.*
    FROM test4 as A INNER JOIN (SELECT GroupNo, Max(LVDate) AS Latest FROM test4 GROUP BY GroupNo) AS B ON A.GroupNo=B.GroupNo AND A.LVDate=B.Latest
    Last edited by CJ_London; 01-06-2016 at 04:09 AM. Reason: missed a bit of criteria

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    Just realised you have duplicate records - so change the SELECT to SELECT DISTINCT

  4. #4
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Thank you for helping me . It works . I didn't know can do this way. I think the first one more easier to understand hahaha .

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

Similar Threads

  1. Replies: 2
    Last Post: 04-30-2015, 08:40 PM
  2. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  3. Replies: 5
    Last Post: 04-03-2012, 07:24 AM
  4. Replies: 14
    Last Post: 01-12-2012, 05:03 PM
  5. Replies: 0
    Last Post: 08-01-2009, 12:43 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