So you want the block_ids that have the most recent date, not the most
recent date for each block_id?

On May 7, 1:23 pm, Eleazar <gerrit.kru...@gmail.com> wrote:
> unfortunately that query does not produce the rusult I want. The
> HAVING MAX() seems logical but it doesn't change the results. Problem
> is that the group function groups by seemingly random record, not the
> latest one. If I could sort by date then group that would work, but
> sql does not allow this. Therefore my subquery to fix the problem.
>
> See this article of what I want to 
> do:http://dev.mysql.com/doc/refman/4.1/en/example-maximum-column-group-r...
> If you look in the comments section you will see the query I'm trying
> to implement.
>
> A very strange thing occurred. I called my custom query with some
> joins (basically the one generated by a find, and wrapped with a
> select statement as in my first post) model->query(sql). It works fine
> on my localhost but on the online server the array returned from the
> query is in the form of the alias from the query eg
> [0] -> [alias] -> "all values listed here from all tables joined in
> query"
> [1] -> etc.
>
> On the localhost it keeps the format of
> [0]->[Original table name]->values,
>        [original table name 2]->values
> [1]-> etc.
>
> What on earth could cause this? I have no idea where to begin! Why is
> the returned array not formatted  in the usual way? Why would it work
> on the localhost but not on the online server? Any ideas will be
> appreciated!
>
> On May 7, 4:08 pm, Andy Dirnberger <andy.dirnber...@gmail.com> wrote:
>
>
>
>
>
> > 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.organdhelpothers 
> > > 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 sitehttp://cakeqs.organdhelp 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 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