Reputation: 139
I have this query:
SELECT NAME, date, price
FROM purchase
WHERE Max(date) < '$lastweek'
AND NAME = '$customer'
GROUP BY NAME;
How will the query find the most recent date and check that date with the given date?
Upvotes: 0
Views: 1344
Reputation: 9
You can do this:
SELECT name, MAX(date) as latest_date, price
FROM purchase
WHERE name= '$customer'
GROUP BY name HAVING latest_date = '$date';
Upvotes: 0
Reputation: 14262
Did you try SELECT MAX(date)
from purchase as subquery ?
SELECT NAME, date, price
FROM purchase
WHERE (SELECT Max(date)) < $lastweek
Upvotes: 0
Reputation: 2359
You can try like this:
SELECT NAME, date, price
FROM purchase
WHERE (SELECT Max(date) FROM purchase) < '$lastweek'
AND NAME = '$customer'
GROUP BY NAME;
Upvotes: 1