I have a table like this
Col1 Col2 Mindate MaxDate
A B 12-04-2012 00:12:00:087 31-04-2012 00:00:01:001
C D 01-01-2011 30-01-2011
A B 09-05-2012 27-05-2012
A B 11-07-2012 21-07-2012
I have only inserted datetime in first row but omitied in other rows for brevity, all date columns are datetime.
Assume that I have inserted the last records for A and B (Col1 and Col2 are combined key).
Now I want last record for A amd B based on the mindate which in above case should be
A B 09-05-2012 27-05-2012
I am trying the following query:
SELECT * FROM tbl WHERE Col1 ='A' AND Col2='B' AND ....
You can use
ROW_NUMBER:This would return the second last record according to Mindate and the given key.