2
public function getStatusLimit($array = array()) {
    $this->getSelect()->reset()
        ->union(
            $array
        );

    return $this;
}

$this->_collection->getStatusLimit(array($this->getCollection1()->getSelect(),$this->getCollection2()->getSelect()));

result of query

SELECT `main_table`.*, (SELECT COUNT(*) FROM gn_daily_bidding_history WHERE gn_daily_bidding_history.msisdn_id = main_table.msisdn_id) AS `total_bids`, (SELECT COUNT(DISTINCT(customer_id)) FROM gn_daily_bidding_history WHERE gn_daily_bidding_history.msisdn_id = main_table.msisdn_id) AS `total_bidders` FROM `gn_msisdn_bid_list` AS `main_table` WHERE (cat_id = '3') AND (msisdn_status = '1') AND (bid_start <= '2016-07-12 04:50:30') AND (bid_status != 1) AND (bid_status = 2) AND (bid_end >= '2016-07-12 04:50:30') ORDER BY `main_table`.`bid_end` desc

UNION

SELECT `main_table`.*, (SELECT COUNT(*) FROM gn_daily_bidding_history WHERE gn_daily_bidding_history.msisdn_id = main_table.msisdn_id) AS `total_bids`, (SELECT COUNT(DISTINCT(customer_id)) FROM gn_daily_bidding_history WHERE gn_daily_bidding_history.msisdn_id = main_table.msisdn_id) AS `total_bidders` FROM `gn_msisdn_bid_list` AS `main_table` WHERE (cat_id = '3') AND (msisdn_status = '1') AND (bid_start <= '2016-07-12 04:50:30') AND (bid_status = 3) AND (bid_end <= '2016-07-12 04:50:30') ORDER BY `main_table`.`bid_end` desc

not wrapping with query with "()"

2

use Zend_Db_Select::SQL_UNION_ALL

public function getStatusLimit($array = array()) {
    $this->getSelect()->reset()
        ->union(
            $array, Zend_Db_Select::SQL_UNION_ALL
        );

    return $this;
}
  • 1
    i also use with concate like $this->_collection->getStatusLimit(array('('. $this->getCollection1()->getSelect(). ')', '('. $this->getCollection2()->getSelect()->limit(3). ')')); – Arshad Muhammad Jul 12 '16 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.