That explains your problem better :). Do you need all the data from that query? Or only photo_id? In case you just need the photo_id you can do: $photoIds = $this->Hotel->findAll("hotel_id = '$hotel_id'", "DISTINCT photo_id");
Using GROUP BY when there is no agregation function in SELECT clause somehow works in MySQL (I didn't believe that until I checked this myself), but for example, in MSSQL this raises an error. I think that MySQL is here not compliant with the standard. On 21 Sty, 16:01, cronet <[EMAIL PROTECTED]> wrote: > Thanks for your replies! > > @Claudia, I will try this! > > @Marcin > > I think an order by is not enough in this case. > > There are multiple entries with the same photo_id, but different > descriptiontype_id's ... But at the end they are the same photos. Only > in different categories (descriptiontypes). This structure is fixed by > an webservice, so no possibility to change that fact. > > But i want to show them only once (it doesn't matter which category). > > So an simple ORDER would not prevent showing the same photo. > > I would use an DISTINCT, but i neet other informations too, so google > said (:) I should rather use a GROUP BY clause... > > On 21 Jan., 12:03, Marcin Jaworski <[EMAIL PROTECTED]> wrote: > > > I don't see a reason for using grouping in this query. 'Group by' is > > only needed if you want to use some aggregation functions like SUM, > > AVG, MAX, MIN etc. If you don't use them, you don't need 'group by' in > > your query. I think that use of 'order by' would be enough in your > > situation, so you need to add an order value to findAll to order it by > > photo_id. > > > On 20 Sty, 23:10, cronet <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I'm siting here for about 2 hours and get it not work. I need a simple > > > group by in an association. > > > > This is in my controller: > > > > $this->Hotel->bindModel( > > > array('hasMany' => > > > array( > > > 'HotelDescriptionTranslation' => array( > > > 'className' => > > > 'HotelDescriptionTranslation', > > > 'foreignKey' => > > > 'hotel_id', > > > 'conditions' => > > > $cond1 > > > > > > ), > > > 'HotelDescriptionPhoto' => array( > > > 'className' => > > > 'HotelDescriptionPhoto', > > > 'foreignKey' => > > > 'hotel_id', > > > 'conditions' => > > > $cond2 > > > ) > > > ) > > > ), FALSE > > > ); > > > $hotel = $this->Hotel->findByHotelId($hotel_id); > > > > Results in this query: > > > > SELECT `HotelDescriptionPhoto`.`id`, > > > `HotelDescriptionPhoto`.`descriptiontype_id`, > > > `HotelDescriptionPhoto`.`hotel_id`, > > > `HotelDescriptionPhoto`.`photo_id`, > > > `HotelDescriptionPhoto`.`url_max300`, > > > `HotelDescriptionPhoto`.`url_original`, > > > `HotelDescriptionPhoto`.`url_square60`, > > > `HotelDescriptionPhoto`.`created`, `HotelDescriptionPhoto`.`modified` > > > FROM `hotel_description_photos` AS `HotelDescriptionPhoto` WHERE > > > (descriptiontype_id = '5' OR descriptiontype_id = '10') AND > > > `HotelDescriptionPhoto`.`hotel_id` IN (60160) > > > > But I need a "GROUP BY `HotelDescriptionPhoto`.`photo_id`" inside the > > > query... > > > > Is there an easy(?!) way to achieve this? (I would not want to create > > > a custom query)... > > > > Regards, > > > Alexander --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---