Search code examples
phpmysqlzend-frameworkzend-dbzend-db-table

How to convert nested sql query to zend 1.12 format


My Query:

select distinct ml.send_to from message_log as ml where NOT exists
(select mobile_no from user_details WHERE user_details.mobile_no = ml.send_to);

Solution

  • $select1 = $db->select()->from('user_details',array('mobile_no'))
                      ->where('user_details.mobile_no = ml.send_to');
    
    $select2 = $db->select()->distinct()
                   ->from(array('ml'=>'message_log'), array('ml.send_to')))
                   ->where('NOT EXISTS ?', $select1);
    

    This will do the trick in the easiest way.