1
  Table : sc_message 
  ______________________________________________________________________
 |message_id | message_sender_id | message_receiver_id | message_content|
 ------------------------------------------------------------------------  

Table : sc_user 
  _____________________
 | user_id | user_name |
 ----------------------- 

Table : sc_message_slave

| message_slave_id | message_slave_sender_id | message_slave_receiver_id | message_slave_content | message_slave_sent_on |

 $Query_1 = $this ->select()
                  ->from(array('msg' => 'sc_message'), array('msg.message_sender_id', 'msg.message_receiver_id', 'msg.message_content', 'msg.message_sent_on'))
                  ->join(array('usr' => 'sc_user'), 'msg.message_sender_id = usr.user_id', array('usr.user_name as sender_name'))
                  ->where('msg.message_id = ?',$message_id)
                  ->setIntegrityCheck(false);


 $Query_2 = $this ->select()
                     ->from(array('msg_slv' => 'sc_message_slave'), array('msg_slv.message_slave_sender_id', 'msg_slv.message_slave_receiver_id','msg_slv.message_slave_content', 'msg_slv.message_slave_sent_on'))
                     ->join(array('usr' => 'sc_user'), 'msg_slv.message_slave_sender_id = usr.user_id', array('usr.user_name as sender_name'))
                     ->where('msg_slv.message_id = ?',$message_id)
                     ->setIntegrityCheck(false);            
 $select = $this ->select()
                    ->union(array($Query_1, $Query_2))
                    ->order('msg.message_sent_on')
                    ->setIntegrityCheck(false);

It gives me warning like this and execution stops there ..

Warning: Invalid use of table with UNION in E:\wamp\www\social_site\library\Zend\Db\Select.php on line 1222 

can you please tell me what is wrong with the query?

1
  • Try doing Zend_Debug::dump($select->__toString()); to get the query. will be easier to debug. Commented Apr 16, 2012 at 8:49

1 Answer 1

1

Since you have an order by where you do the union, you probably ran into this issue:

http://framework.zend.com/issues/browse/ZF-4338

They won't fix the issue, you can read as to why, but someone posted a work around.

$select_1 = $db->select()->...;
$select_2 = $db->select()->...;

$main_select = $db->select()->union( array(  '('.$select_1.')',  '('.$select_2.')' ) );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.