views:

19

answers:

1

Hi, I need to execute the following mysql query in Zend;I am not an excpert with Zend framework

SELECT  `optionride`.`featureoption_id`,
`optionride`.`featureoptionride_id`,`foption`.`featureoptionblock_id`,

`foption`.`labelname`,`optionride`.`value` FROM 
`engine4_ride_featureoptionrides` AS `optionride` 
LEFT JOIN `engine4_ride_featureoptions` AS `foption` 
ON foption.featureoption_id = optionride.featureoption_id 
WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )

UNION

SELECT `foption`.`featureoption_id`,  null as    
`featureoptionride_id`,`foption`.`featureoptionblock_id`,
`foption`.`labelname`,null as `value` FROM `engine4_ride_featureoptions` AS `foption`
WHERE (foption.featureoptiontab_id= '2' ) AND `foption`.`featureoption_id` NOT IN
(
   SELECT `optionride`.`featureoptionride_id` FROM `engine4_ride_featureoptionrides`   
   AS `optionride` 
   LEFT JOIN `engine4_ride_featureoptions` AS `foption` ON 
   foption.featureoption_id   =      optionride.featureoption_id 
  WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )
 )

Anybody can help me please.

A: 

You can put all your query asis in the $db->fetch().

Also you can use $db->select()->union(array($sql1, $sql2)), where $sql1, $sql2 can be $db->select() or a string ("select...").

For the NOT IN you can use $db->where('someField NOT IN (?)', array());

mauromartini