I would like to convert an Access query with the last keyword to SQL Server 2005 but cannot figure it out any help is appreciated.
The query in Access is
SELECT field1, field2, Last(field3) , Last(field4) , Last(DateField)
FROM table
GROUP BY field1, field2
HAVING (((Last(DateField)) Between #9/1/2012# And #9/30/2012#));
I have tried to sort Datefield in descending order in SQL and used the MIN keyword on datefield but to no avail, also in SQL I have to group by all the fields and not just 2 fields as in Access.
Thanks in advance.
try
MAXinstead ofLAST, like this:I don’t understand this at all: I have to group by all the fields If you group by all the fields, it’s equivalent to
SELECT DISTINCT, and performing aggregate functions won’t make sense.