Why use the subquery?

SELECT * FROM mytable WHERE some_id = 1 GROUP BY block_id HAVING
MAX(date)

or:

$Model->find('all', array(
  'conditions' => array('Model.some_id' => 1),
  'group' => ('Model.block_id HAVING MAX(date)'),
);

On May 7, 6:16 am, Eleazar <gerrit.kru...@gmail.com> wrote:
> Hello
> for the life of me I coudn't find an example of how to do the
> following:
> SELECT * FROM (SELECT * FROM mytable WHERE some_id=1 ORDER BY DATE
> DESC) t1 GROUP BY block_id
>
> The query needs to select the latest entries for each block_id in the
> table (like selecting the latest comment for each blog post would be
> an equivalent scenario).
>
> I would need to implement this with pagination, but I would just like
> to get it to work with find() for now.
>
> Is a custom query maybe the only way to do this?
>
> Thanks!
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to