I use mysql 5.1.
This is my DB schema :
id user_id type created_at
1 32 X 2012-11-19
2 32 Y 2012-11-18
3 30 X 2012-11-16
4 32 Z 2012-11-17
5 31 Y 2012-11-13
6 32 Z 2012-11-9
I want that my SQL query returns the user_id, type, and the lastest created_at for each type.
I tried to make this request:
SELECT max(type) FROM notification WHERE user_id=34 ORDER BY type but it returns only the latest created_at.
You cannot do this in really simple query because
GROUP BY(which you are missing by the way in your query) doesn’t guarantee that it won’t return values mixed from multiple rows.