简体   繁体   中英

Codeigniter 2.2 - Active Record update with left join and multiple where clauses

I have the following SQL:

UPDATE msh_leads ml
LEFT JOIN msh_leads_disposition_log dl
ON ml.id = dl.lead_id
SET ml.assigned_to = null
WHERE ((dl.disposition_id != 6 AND dl.disposition_id != 3) OR (dl.disposition_id IS NULL))
AND (ml.assigned_to = ? AND ml.decline = 0 AND ml.subcategory_id = ?)

There is a bit of logic in creating this (some of the where's come and go depending on certain situations) so I was hoping to recreate this in Codeigniter (2.2) Active Record. Im not sure how to add a join to an update or how to add multiple complex where statements to an update.

This'll help you. Try this.

Note: you need to place your values over ? else it'll throw an error 1064

$this->db->set('ml.assigned_to', 'null');
$this->db->where('ml.assigned_to = ?');
$this->db->where('((dl.disposition_id != 6 AND dl.disposition_id != 3) OR (dl.disposition_id IS NULL))');
$this->db->where('ml.decline = 0');
$this->db->where('ml.subcategory_id = ?');
$this->db->update('msh_leads ml join msh_leads_disposition_log dl on ml.id = dl.lead_id');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM