Here is my problem, I have this request (it works) but I would like to replace the TO_DAYS(notification.created_at) by the latest action of the user.
I tried to use TO_DAYS(MAX(notification.created_at)) but it returns "#1111 - Invalid use of group function".
SELECT user.email, notification.type, max(notification.created_at) AS date
FROM user, notification
WHERE (user.id = notification.user_id) AND (TO_DAYS(NOW()) - TO_DAYS(notification.created_at) >= 30)
GROUP BY user.id
ORDER BY `date` DESC
When using aggregate functions like MAX, you have to use HAVING and not WHERE, it’s possible to use both on the same command, however HAVING will always come after WHERE and GROUP BY.
for more info : http://www.w3schools.com/sql/sql_having.asp