views:

42

answers:

2

Basically i need to have this query done through zend framework.

SELECT k.id AS ID ,k.name AS NAME ,k.ppu_sell AS PRICE, k.type as TYPE FROM `inventory` as k UNION
select m.id AS ID, m.name AS NAME, m.price AS PRICE, 'menu' as TYPE FROM menu as m
A: 

http://stackoverflow.com/questions/1319611/zend-framework-select-objects-and-union

Yanick Rochon
that is not very helpful. don't consider it duplicate answer. I need it written for idiots cuz i've been troubling my mind here and it doesn't seem to work.
I'm sorry if you didn't find that link "helpful", however what you accepted as solution was already proposed and accepted there. Therefore, this is a duplicate. Don't say this is not a duplicate because the other question is not *exactly* what you're asking for.
Yanick Rochon
+1  A: 

Try this:

    $select = Zend_Db_Table::getDefaultAdapter()->select();
    $select->from(
        array('inventory' => 'k'),
        array(
            'ID'    => 'k.id',
            'NAME'  => 'k.name',
            'PRICE' => 'k.ppu_sell',
            'TYPE'  => 'k.type'));

    $selectClone = clone $select;

    $select->reset()->from(
        array('menu' => 'm'),
        array(
            'ID'    => 'm.id',
            'NAME'  => 'm.name',
            'PRICE' => 'm.price',
            'TYPE'  => new Zend_Db_Expr("'menu'")));

    $select = Zend_Db_Table::getDefaultAdapter()->select()->union(array(
        $selectClone, $select
    ));
DimaKrasun
thank you for your time.
thank you for using zend framework
DimaKrasun