0
votes

I have code:

$balanceModelCredit = new Model_BalanceCredit();
$balanceModelDebt = new Model_BalanceDebt();

$selectQueryDebt = $balanceModelDebt->select()
    ->from('balance_debt', array('date',
        'amount',
        'description',
        new Zend_Db_Expr('"koszta"')
    ));
$selectQueryDebt->where('balance_id=?', $balance_id);

$selectQueryCredit = $balanceModelCredit->select()
    ->from('balance_credit', array('date',
                             'amount',
                             'description',
                             new Zend_Db_Expr('"przychod"')
    ));
$selectQueryCredit->where('balance_id=?', $balance_id);

How can I do UNION statement?

1
Your queries return different columns. Union can be use only when each query returns the same set of columns. - Daniel Gadawski
@DanielGadawski : Sorry, UNION only need to have equal columns count and same column types but it does not matter about column names, ... - php-dev

1 Answers

0
votes

You only need to do :

$selectQueryCredit->where('balance_id = ?', $balance_id);

$selectQueryCredit->union(array($selectQueryDebt));

Hope it helps.