2014-05-17 13 views
0

我有代码:Zend_Db的 - 工会

$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); 

我该怎么办联合声明?

+0

您的查询返回不同的列。仅当每个查询返回相同的一组列时,才可以使用联合。 –

+0

@DanielGadawski:对不起,'UNION'只需要有相同的列数和相同的列类型,但对列名无关紧要...... –

回答

0

你只需要做:

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

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

希望它能帮助。