Иногда в инстеллере (или где-нибудь в коде) нужно обновить несколько таблиц с джойном:
UPDATE `maintable` AS `t1`
INNER JOIN `maintable`
LEFT JOIN `sales_flat_order` AS `t2` ON t1.application_id = t2.increment_id
SET `t1`.`student_id` = `t2`.`applicant_id`
WHERE (t1.student_id IS NULL)
Тогда я делаю вот так:
$adapter = $this->_getWriteAdapter();
$select = $adapter->select()
->from($this->getMainTable(), array())
->joinLeft(array('t2'=>$this->getTable('sales/order')),
"t1.application_id = t2.increment_id",
array('stud_id' => 'appl_id')
)
->where('t1.stud_id IS NULL');
$query = $adapter->updateFromSelect(
$select,
array('t1' => $this->getMainTable())
);
$adapter->query($query);
В результате получается вот такой селект:
UPDATE `maintable` AS `t1`
INNER JOIN `maintable`
LEFT JOIN `sales_flat_order` AS `t2` ON t1.application_id = t2.increment_id
SET `t1`.`student_id` = `t2`.`applicant_id`
WHERE (t1.student_id IS NULL)