Results 1 to 5 of 5
  1. #1
    martinhough is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    4

    Query: select latest date within given category

    Hi

    A basic one I think but stumping my limited knowledge;-

    I need to run a query from 3 tables. 'Detail', 'RiskAssessments' and 'Subject Area' where I only need the latest date of the repspective 'Detail' entry.

    My SQL currently looks like this;-

    SELECT RiskAssessments.DateofRA, Detail.Detail, RiskAssessments.PSR, RiskAssessments.PLR, [detail.psr]*[revised plr] AS RRN
    FROM ([Subject Area] INNER JOIN Detail ON [Subject Area].ID = Detail.[Subject Area]) LEFT JOIN RiskAssessments ON Detail.ID = RiskAssessments.DetailID
    GROUP BY RiskAssessments.DateofRA, [Subject Area].SubjectArea, Detail.Detail, RiskAssessments.PSR, RiskAssessments.PLR, [detail.psr]*[revised plr]
    HAVING ((([detail.psr]*[revised plr])>8));

    This returns all instances (previous to the latest date) of each 'Detail' which meets the requirements of 'RRN' being greater than 8; I only require the latest of each group ('Detail') that meets this.

    Any help much appreciated.

    Thanks

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    So, call that whole thing Query1 and wrap it by
    Code:
    SELECT 
       Q1.Detail,
       Q1.DateofRA, 
       Q1.PSR, 
       Q1.PLR, 
       Q1.RRN
    FROM Query1   
    WHERE Q1.DateofRA = 
        (SELECT MAX(Q2.DateofRA)
         From Query1 AS Q2
         WHERE Q1.Detail = Q2.Detail);

  3. #3
    martinhough is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    4
    See, told you it was easy!

    Ha, ha. Seriously - thank you very much - I've learnt something there. Brilliant.

  4. #4
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Hopefully that means it worked. These kinds of correlated subquery are notoriously "fiddly".

  5. #5
    martinhough is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    4
    Yes indeed Dal - Thank you - works a treat!

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

Similar Threads

  1. Replies: 1
    Last Post: 05-09-2013, 09:13 AM
  2. Query to Extract records with latest date
    By rkalapura in forum Queries
    Replies: 2
    Last Post: 03-13-2013, 05:48 AM
  3. Replies: 7
    Last Post: 11-29-2012, 11:36 AM
  4. Query for latest date? what am I doing wrong?
    By Overdive in forum Queries
    Replies: 1
    Last Post: 12-18-2009, 06:04 AM
  5. Query to find latest date
    By Lockrin in forum Access
    Replies: 2
    Last Post: 12-16-2009, 10:00 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