I have a tableA
of date ranges:
tranid item startdate enddate
---------------------------------------
1 A 1/1/2000 2/2/2005
2 A 5/1/2000 2/2/2005
3 B 7/8/2015 9/8/2015
4 C 4/10/2007 7/20/2008
5 C 4/10/2003 7/20/2005
How to write a SQL query to only select the most recent transactions (ex the most recent start and end dates)?
For example, for A, the most recent date range is 5/1/2000 to 2/2/2005 and for C, the most recent date range is C 4/10/2007 to 7/20/2008.
I am at a complete loss to write this because it seems easy but is not.
select item, max(enddate), max(startdate)
from tableA
where max(enddate)
group by item, enddate, startdate
SQL Server returned an error related to 'having' on something like that - a problem with aggregates.
gracias :)