I have 2 tables parent, children with relation 1:M. I need a pagination. I use SELECT with JOIN. For 1 parent i have some children. If I try to make LIMIT 10 this query get total 10 rows. But i need to get only 10 rows from table parent with all relations. How can I do it?
Sorry for my english. Thank you in advance.
Mysql query:
SELECT `o`.`id` AS `order_id`, `od`.`id` AS `order_destination_id` FROM `order` AS `o`
LEFT JOIN `order_destination` AS `od` ON o.id = od.order_id LIMIT 5
Zend framework:
$select = $this->select()
->setIntegrityCheck(false)
->from(array('o' => 'order'), array('order_id' => 'id'))
->joinLeft(array('od' => 'order_destination'), 'o.id = od.order_id', array('order_destination_id' => 'id'))
->limit(5);
I don’t know about the Zend Framework. Here a plain SQL solution: