Hi
I have a table of data with duplicate entries for actions that have happened to the same unique ID (Initial_UBRN).
I have got a query that will find just the rows where the latest action - [ACTION Date] field - happened but this gives me
duplicates as there may have been more than one action on the latest date. I am trying to work out
how to go one step further and just pick up one of these duplicated entries. It doesn't
matter which one of the duplicates I return. However this one extra step in a single SQL query is too much for my brain to gasp! I thought fundamentally it is because my subquery is only grouped by Initial_UBRN so I tried adding [ACTION Date] to the GROUP BY statement in the sub-query but then I get all the rows returned, not just the Max(ACTION Date) row. Grouping by MaxACTIONDate isn't allowed and gives an error.
SELECT bk1.*
FROM Book_All_Prov_East AS bk1
INNER JOIN (
SELECT Initial_UBRN, Max([ACTION Date]) AS MaxActionDate FROM Book_All_Prov_East GROUP BY [Initial_UBRN]) AS bk2 ON (bk1.[ACTION Date] = bk2.MaxActionDate) AND (bk1.[Initial_UBRN]=bk2.[Initial_UBRN]);
Any ideas?
I have a table of data with duplicate entries for actions that have happened to the same unique ID (Initial_UBRN).
I have got a query that will find just the rows where the latest action - [ACTION Date] field - happened but this gives me
duplicates as there may have been more than one action on the latest date. I am trying to work out
how to go one step further and just pick up one of these duplicated entries. It doesn't
matter which one of the duplicates I return. However this one extra step in a single SQL query is too much for my brain to gasp! I thought fundamentally it is because my subquery is only grouped by Initial_UBRN so I tried adding [ACTION Date] to the GROUP BY statement in the sub-query but then I get all the rows returned, not just the Max(ACTION Date) row. Grouping by MaxACTIONDate isn't allowed and gives an error.
SELECT bk1.*
FROM Book_All_Prov_East AS bk1
INNER JOIN (
SELECT Initial_UBRN, Max([ACTION Date]) AS MaxActionDate FROM Book_All_Prov_East GROUP BY [Initial_UBRN]) AS bk2 ON (bk1.[ACTION Date] = bk2.MaxActionDate) AND (bk1.[Initial_UBRN]=bk2.[Initial_UBRN]);
Any ideas?