开发者

Nested Select using Zend Db

I have a query like

select empl.idemp ,(select em.firstnm from tbl_employeemaster em where em.idemp = empl.approvedby) as approvedby from tbl_empleaveapplicat开发者_JAVA百科ion empl
join tbl_employeemaster emp on empl.idemp = emp.idemp
join tbl_leavemaster lvm on empl.idleavemaster = lvm.idleavemaster

I need to use zend db to build this type of query


Here is how you can convert your string query into Zend_Db_Select

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜