Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Verschachtelte Auswahl mit Zend Db

So können Sie Ihre String-Abfrage in Zend_Db_Select umwandeln

class Empleaveapplication extends Zend_Db_Table_Abstract
{
    protected $_name = 'tbl_empleaveapplication';
}

$table = new Empleaveapplication();

// create sub query
$subSql = $table->select()
                ->setIntegrityCheck(false)
                ->from(array('em' => 'tbl_employeemaster'), array('firstnm'))
                ->where('idemp = empl.approvedby', '');

// main query
$sql = $table->select()
             ->setIntegrityCheck(false)
             ->from(array('empl' => 'tbl_empleaveapplication'), array('idemp', 'approvedby' => new Zend_Db_Expr('(' . $subSql . ')')))
             ->joinInner(array('emp' => 'tbl_employeemaster'), 'empl.idemp = emp.idemp', array())
             ->joinInner(array('lvm' => 'tbl_leavemaster'), 'empl.idleavemaster = lvm.idleavemaster', array());