UNION而不是在使用Zend框架的Mysql操作中

时间:2010-10-23 08:39:08

标签: zend-framework zend-db zend-db-table

我需要在Zend中执行以下mysql查询;我不是Zend框架的超级用户

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' )
 )

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

您可以将所有查询asis放在$ db-> fetch()。

你也可以使用 $ db-> select() - > union(array($ sql1,$ sql2)),其中 $ sql1 $ sql2 可以是 $ db-> select()或字符串(“select ...”)。

对于 NOT IN ,您可以使用 $ db-> where('someField NOT IN(?)',array());