How to use union in zend db

后端 未结 3 1007
小蘑菇
小蘑菇 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:40

    For future reference, in Zend Framework 2.3 this is done with combine.

    For example:

        use \Zend\Db\Sql\Select;
        use \Zend\Db\Sql\Sql;
    
        $sql = new Sql(/* ADAPTER HERE */);
    
        $tag1 = new Select( ['a' => 'articles'] );
        $tag1->columns( [ 'tag' => 'first_tag'] );
        $tag1->where->in('a.id', $articleIds);
    
        $tag2 = new Select( ['a' => 'articles'] );
        $tag2->columns( [ 'tag' => 'second_tag'] );
        $tag2->where->in('a.id', $articleIds);
        $tag2->combine($tag1);
    
        $tag3 = new Select( ['a' => 'articles'] );
        $tag3->columns( [ 'tag' => 'third_tag'] );
        $tag3->where->in('a.id', $articleIds);
        $tag3->combine($tag2);
    
        $statement = $sql->prepareStatementForSqlObject($tag3);
    

提交回复
热议问题