Hello group,

I have an SQL statement which pulls data from a table as follows:

" SELECT tblSites.sites_siteno, " & _
" tblSites.sites_sitename, " & _
" Sum(tblStockResults.stkr_result) AS SumOfstkr_result, " & _
" Sum(tblStockResults.stkr_takings) AS SumOfstkr_takings, " & _
" Sum(tblStockResults.stkr_gp) AS SumOfstkr_gp, " & _
" last(tblStockResults.stkr_closestkval) AS LastOfstkr_closestkval,
" & _
" Last(tblStockResults.stkr_SoHDays) AS LastOfstkr_SoHDays, " & _
" Last(tblStockResults.stkr_endat) AS LastOfstkr_endat, " & _
" sum(tblStockResults.stkr_cashdiff) as SumOfstkr_cashdiff, " & _
" sum(tblstockresults.stkr_resultcost) as SumOfstkr_resultcost "
" FROM tblSites " & _
" INNER JOIN tblStockResults " & _
" ON tblSites.sites_siteid = tblStockResults.stkr_siteid " & _
" WHERE tblStockResults.stkr_endat Is Not Null " & _
" GROUP BY tblSites.sites_siteno, tblSites.sites_sitename; "

The three 'last' statements must be the latest values (by date -
stkr_endat) from that particular site (siteid) but the 'sum' statements
must remain as a sum of all values from that site.

However, if the data is originally fed into the table out of date order
then this always pulls up the last record to be physically entered
instead of the latest record by date (if that makes sense!)

How can I change this so that it always pulls up the latest dated
record (from stkr_endat) and not just the last one to be entered?

Thanks in advance,

Alan