简体   繁体   English

Codeigniter 2.2 - 使用左连接和多个where子句的Active Record更新

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

I have the following SQL: 我有以下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. 创建它有一些逻辑(根据某些情况,某些地方来来去去)所以我希望在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. 我不知道如何将连接添加到更新或如何将更复杂的where语句添加到更新。

This'll help you. 这对你有所帮助。 Try this. 试试这个。

Note: you need to place your values over ? 注意:您需要将值放在 else it'll throw an error 1064 否则它会抛出错误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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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