I'm having trouble with a query using "MAX". In my query I'm trying to use 2 date columns as my criteria. Here is the format for each column:
Date1:
01/01/2007
Date2:
200701
For my query, I'm trying to pull the Date1 values where the month of Date1 equals the Max month of Date2. Here is my coding:
Select Date1
FROM Table1
WHERE Month(Date1) = MAX(RIGHT(Date2 , 2))
But I'm getting the error: "An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference".
I'm not exactly sure what I'm doing wrong. If someone could help me with some examples, I'd greatly appreciate it.
Thanks!
Date1:
01/01/2007
Date2:
200701
For my query, I'm trying to pull the Date1 values where the month of Date1 equals the Max month of Date2. Here is my coding:
Select Date1
FROM Table1
WHERE Month(Date1) = MAX(RIGHT(Date2 , 2))
But I'm getting the error: "An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference".
I'm not exactly sure what I'm doing wrong. If someone could help me with some examples, I'd greatly appreciate it.
Thanks!
Comment