Hello All,

I'm having trouble building a condition for findAll().

I have a model of post revisions. There are post_id's, and for each
post_id, there are one or more revisions. Here's what it looks like:

id  post_id  revision  data...
1     1          1           blah
2     1          2           blah
3     2          1           blah
4     1          3           blah
5     2          2           blah
6     3          1           blah

In the above, I don't actually use id; it's all about searching for a
specified post_id, either with a specified revision, or (more commonly)
the highest revision.

I need to build a condition for findAll() such that it returns one row
for each post_id, with the highest revision for that post_id.

The closest I have is "GROUP BY post_id", which returns one row for
each post_id, however the row returned is the lowest revision, not the
highest.

Also, I need to build a condition for find($post_id) such that it
returns the row for post_id with the highest revision for that post_id.

I came up with this, which seems to work:
   revision=(SELECT MAX(revision) FROM posts WHERE post_id=$post_id)

Is there a better way to do that one as well?

Thanks


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