423,822 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,822 IT Pros & Developers. It's quick & easy.

Cannot have Aggregate Function in Where Clause Error

anoble1
100+
P: 216
I need some help.
I am getting this error when I changed the SQL statement and added the function "LAST"

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT Last(tblEntrys.OdometerReading) AS LastOfOdometerReading, Last(tblEntrys.DateEntered) AS LastOfDateEntered FROM tblEntrys WHERE (((tblEntrys.Vehicle) = " & Vehicle & ") And Last(((tblEntrys.DateEntered)) < #" & Now() & "#)) ORDER BY Last(tblEntrys.DateEntered) DESC;"
I am missing something. But, I cannot find it. I am looking for the last date one of our vehicles data was entered so I can grab the last date to get that mileage that was put in.
May 16 '18 #1

✓ answered by Rabbit

LAST is an aggregate function. You can't have aggregate functions in the WHERE clause. To filter on an aggregate function, you have to use the HAVING clause.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,279
LAST is an aggregate function. You can't have aggregate functions in the WHERE clause. To filter on an aggregate function, you have to use the HAVING clause.
May 16 '18 #2

anoble1
100+
P: 216
Awesome. That worked like a champ!
May 16 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.