I tried:

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

but it still gave the same result, (ie first post and not last post).

Or did I miss something?

Additionally I'm using MySQL as the backend DB to a php app. I know I can do all this 
in php, but consider MySQL the proper place to do this stuff...

Darran 

-----Original Message-----
From: Donny Simonton
Sent: Monday, 8 March 2004 13:49
To: Darran Kartaschew; [EMAIL PROTECTED]
Subject: RE: SELECT ... GROUP BY


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 
> 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]

Reply via email to