Warning: SQL noobie...
I'm trying to create a query where the most recent entry for each user is returned from a forum table, and sorted by username. The fields are simply: user_id, username, post, last_updated. No primary key defined.
I've tried the simple SELECT * FROM posts GROUP BY user_id DESC ORDER BY username. It returns what I'm after, but not the lastest post from each user, (but the first post). Now my understanding of the GROUP BY function may not be correct, but according to the MySQL manual adding DESC after GROUP BY shold return what I'm after but doesn't. Any hints?
(Table type is InnoDB if that matters, running on MySQL 4.0.16).
I'm trying to create a query where the most recent entry for each user is returned from a forum table, and sorted by username. The fields are simply: user_id, username, post, last_updated. No primary key defined.
I've tried the simple SELECT * FROM posts GROUP BY user_id DESC ORDER BY username. It returns what I'm after, but not the lastest post from each user, (but the first post). Now my understanding of the GROUP BY function may not be correct, but according to the MySQL manual adding DESC after GROUP BY shold return what I'm after but doesn't. Any hints?
(Table type is InnoDB if that matters, running on MySQL 4.0.16).