How to use union in zend db

后端 未结 3 1008
小蘑菇
小蘑菇 2021-01-13 07:10

In sql i am using union i don\'t know how to write it in zend db.

select m.*, 0 as is_shared from test m where user_id = $userId 
union
select m.*,1 as is_sh         


        
3条回答
  •  广开言路
    2021-01-13 07:21

    According to the Zend_Db_Select documentation, you can create one query for each member of the union (they can be strings or Zend_Db_Select objects themselves), and then call the union() method of Zend_Db_Select.

    Something like:

    $sql1 = FIRSTPARTOFTHEQUERY;
    $sql2 = SECONDPARTOFTHEQUERY;
    $select = $db->select();
    $select->union(array($sql1, $sql2));
    

    Hope that helps,

提交回复
热议问题