KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am having some problems turning the SQL below into a Zend Db query. $select = ' SELECT s.id, i.id as instance_id, i.reference, i.name, i.sic_code, i.start_date FROM sles s JOIN sle_instances i ON s.id = i.sle_id WHERE i.id = ( SELECT MAX(id) FROM sle_instances WHERE sle_id = s.id ) ORDER BY i.name ASC'; I have got as far as the code before - but Zend Db isn't producing the query correctly. Can any one show me what I missing?? $select = $db->select() ->from('sles', array( 'id', 'instance_id' => 'sle_instances.id', 'reference' => 'sle_instances.reference', 'name' => 'sle_instances.name', 'sic_code' => 'sle_instances.sic_code', 'start_date' => 'sle_instances.start_date' ) ) ->join('sle_instances', 'sles.id = sle_instances.sle_id') ->where('sles.id = (SELECT MAX(id) FROM sle_instances WHERE sle_id = sles.id)') ->order('sle_instances.name ASC'); The SQL does work by the way. I am rewriting it using Zend Db as I wish to use the Zend Paginator functionality. Any help is greatly appreciated. PJ
Tags (comma-separated)
Save Edits
Cancel