Friday, October 19, 2012

Re: Cakephp find order by then group by

@euromark, that works, but is it really safe?

To best of my knowledge and experience with MySQL, using MAX (and other aggregate friends) with other fields in the same query does not necessarily ensure that other fields will correspond to the same row! Correct me if I'm wrong, but this is how I interpreted the MySQL documentation.

For instance SELECT id, MAX(price), product_type .... GROUP BY (product_type) is not a 100% way to get the ID of the record with the highest price. Which is odd to me, but I've been tackling this problem for ages now and this example made me question this approach.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: