I'm trying to retrieve the event ID and endDate from a list that includes multiple endDates for the same ID. That step was easy enough using max() and grouping, but where I am struggling is then restricting those results to only those where the max end date has already passed.
I believe this requires the use of nested SQL, but I just can't get it to work.
Records:
eventID | endDate
1 05/01/2015
1 05/01/2014
1 05/01/2013
2 05/01/2016
3 07/01/2016
4 05/01/2014
4 05/01/2013
Desired results (where today = June 2015):
eventID | endDate
1 05/01/2015
4 05/01/2014
This code gets me the list of all events and their max end date, and from this I need to get the ContentID and EndDate where the EndDate is before today. I've tried adding a where statement to limit the date but that gets executed prior to the max(event.EndDate) which doesn't get me the results I need.
select event.ContentID, max(event.EndDate) as EndDate
from event
group by event.ContentID
Any help would be much appreciated!