I will give an example: Advert hasMany Option I need to find Adverts, where its Options are 3 and 4 values. When using IN, it will return results with 3, or, 4, or both 3 and 4. But i want only with both values.
Like: [0] => Array ( [Advert] => Array ( [id] => 2 [code] => 54 [created] => 2008-12-19 11:17:30 ) [Option] => Array ( [0] => Array ( [id] => 1 [advert_id] => 2 [option] => 3 ) [1] => Array ( [id] => 2 [advert_id] => 2 [option] => 4 ) ) ) On Dec 24, 12:35 am, Smelly_Eddie <ollit...@gmail.com> wrote: > How can the same field have multiple values? > -it can be = '3' > -it can be= '4'' > > Otherwise maybe your are just concatenating multiple variables into > one, e.g.; > -it can be='3,4' > which probably should be evaluated for best practices.. > > You would not use IN in such a case. > > If the are always ordered numerically you might use; > AND options.option like '%3,4%' > (assuming there are higher or lower values (2,..,5)) > > If they are not always order and could be 4,3 or 4,5,3 then you might > try; > AND options.option like '%3%' AND options.option like '%4% > > On Dec 22, 11:21 am, dev <minde...@gmail.com> wrote: > > > i'm building custom SQl query and need a little help. > > > query: > > select distinct adverts.id, adverts.code from adverts left join images > > on (images.advert_id = adverts.id) left join options on > > (options.advert_id = adverts.id) where (SELECT count(1) FROM images > > WHERE adverts.id = images.advert_id) > 0 AND options.option IN (3, 4); > > > but i want to get all Advert records, where options.option has all > > these values (3,4). When i'm using IN(), these values are with OR > > operator, how to set AND? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---