Bishwajit Kumar
Bishwajit Kumar

Reputation: 3

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

Upvotes: 0

Views: 98

Answers (2)

Ignacio Ruiz
Ignacio Ruiz

Reputation: 621

$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.

Upvotes: 1

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

you can use customer query in zend as

$sql = '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);';

 $stmt = new Zend_Db_Statement_Mysqli($db, $sql);
 $stmt->execute();
 while ($row = $stmt->fetch()) {
   echo $row['send_to'];
 }

this will really help you

http://framework.zend.com/manual/1.12/en/zend.db.statement.html

Upvotes: 0

Related Questions