You should change it to something like this:

Select * from posts group by user_id order by username, timestamp DESC

That should give you the last post.

Donny

> -----Original Message-----
> From: Darran Kartaschew [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 07, 2004 9:42 PM
> To: [EMAIL PROTECTED]
> Subject: SELECT ... GROUP BY
> 
> Warning: SQL newbie...
> 
> 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 sorta returns what I'm after, but not the latest 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 should return what I'm after but doesn't appear to do so.
> Any hints?
> 
> PS. Table type is InnoDB, running on MySQL 4.0.16-max-nt.
> 
> Darran
> 
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
> 




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to