Max Date from Sub Query
I am running CF 8 and my backend is MS SQL 2005. I am attempting to create a recordset that will list all applicants along with their most recent training date. I have two tables, AppInfo and TrainInfo that are tied together with a primary/foreign key. For some reason in my list I do get all applicants listed but not their most recent training date. I have 3 training dates that belong to one TrainInfo.AppIDFK and 2 training dates that belong to another TrainInfo.AppIDFK but not getting either let alone the most recent.
Here is the code I am using. Can you tell me where I am going wrong? I've been at this for a week now. Any help will be greatly appreciated.
<!--- Query to get App Listing --->
<cfquery name="qApp" datasource="#dsn#">
SELECT AppIDPK, FName, LName, WkPhone, HmPhone,
SubmitDate, Status
FROM AppInfo
ORDER BY LName, FName
</cfquery>
<!--- Query to get training detail --->
<cfquery name="qMaxDate" datasource="#dsn#">
SELECT TrainID, AppIDFK, TrainingDate
FROM TrainInfo
WHERE TrainingDate =
(SELECT MAX(TrainingDate)
FROM TrainInfo
WHERE AppIDFK = #qApp.AppIDPK#)
GROUP BY TrainID, AppIDFK, TrainingDate
</cfquery>
