DoctorV3774
Programmer
I have a fairly simple SQL Statement. I need the Most recent 5 records in descending date order by Agency_Diary_Date_of_Contact for each Producer_code to display. Problem I am having when I use Top 5 in the select statement is that it only shows the most recent 5 for the first producer in the recordset. How can I adjust this so that I get the most recent 5 only for each producer withh all detail. (Some Producers may only have 4 or less recods I just need up to the 5 most recent)
Thanks
SELECT Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact, Agency_Diary.Agency_Diary_ID, Agency_Diary.Agency_Diary_Type_of_Contact, Agency_Diary.Agency_Diary_Agency_Participants, Agency_Diary.Agency_Diary_GAIC_Participants, First(Agency_Diary.Agency_Diary_Notes) AS FirstOfAgency_Diary_Notes
FROM Agency_Diary
GROUP BY Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact, Agency_Diary.Agency_Diary_ID, Agency_Diary.Agency_Diary_Type_of_Contact, Agency_Diary.Agency_Diary_Agency_Participants, Agency_Diary.Agency_Diary_GAIC_Participants
ORDER BY Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact DESC;
Thanks
SELECT Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact, Agency_Diary.Agency_Diary_ID, Agency_Diary.Agency_Diary_Type_of_Contact, Agency_Diary.Agency_Diary_Agency_Participants, Agency_Diary.Agency_Diary_GAIC_Participants, First(Agency_Diary.Agency_Diary_Notes) AS FirstOfAgency_Diary_Notes
FROM Agency_Diary
GROUP BY Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact, Agency_Diary.Agency_Diary_ID, Agency_Diary.Agency_Diary_Type_of_Contact, Agency_Diary.Agency_Diary_Agency_Participants, Agency_Diary.Agency_Diary_GAIC_Participants
ORDER BY Agency_Diary.Producer_Code, Agency_Diary.Agency_Diary_Date_of_Contact DESC;