Got it:

SELECT `p`. * FROM `posts` AS `p` 
WHERE 
`revision` IN (
        SELECT MAX( `revision` ) AS `revision` FROM `posts` AS `p2` 
        WHERE `p2`.`post_id` = `p`.`post_id` 
        GROUP BY `post_id` 
)

This gives you:

id      post_id revision        data  
----------------------------------------
4       1               3               bla bla bla 
5       2               2               bla bla bla 
6       3               1               bla bla bla

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Uncle Bill
Enviado el: Martes, 28 de Noviembre de 2006 03:55 p.m.
Para: Cake PHP
Asunto: Re: help with SQL statement

Thanks, Mariano.

However, I'm looking to pull in a whole record for the given $post_id.
If I extend your suggestion to
  SELECT post_id, MAX(revision), data
I get the data from the older records. Because MAX(revision) is the
field returned, not the WHERE clause.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to