0

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?

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
faszynski
  • 419
  • 3
  • 11
  • 26
  • Your queries return different columns. Union can be use only when each query returns the same set of columns. – Daniel Gadawski May 17 '14 at 19:18
  • @DanielGadawski : Sorry, `UNION` only need to have equal columns count and same column types but it does not matter about column names, ... – php-dev May 18 '14 at 00:07

1 Answers1

0

You only need to do :

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

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

Hope it helps.

php-dev
  • 6,998
  • 4
  • 24
  • 38