是的,這是可能的,但它的棘手:
UPDATE `messages`
SET `from_delete` = IF(`from_user_id` = '6',NOW(),`from_delete`)
, `to_delete` = IF(`to_user_id` = '6',NOW(),`to_delete` )
WHERE (`thread_hash` = 'abc' AND `from_user_id` = '6')
OR (`thread_hash` = 'abc' AND `to_user_id` = '6')
的「絕招」是使用條件的分配。如果行不應該更新,那麼將列的當前值分配給「不變」操作的列。
爲了完整性,您可能希望將thread_hash上的條件添加到條件。雖然這不會改變任何與查詢:
UPDATE `messages`
SET `from_delete` = IF(`thread_hash` = 'abc' AND `from_user_id` = '6'
,NOW(),`from_delete`)
, `to_delete` = IF(`thread_hash` = 'abc' AND `to_user_id` = '6'
,NOW(),`to_delete` )
WHERE (`thread_hash` = 'abc' AND `from_user_id` = '6')
OR (`thread_hash` = 'abc' AND `to_user_id` = '6')
什麼是'它'?你可以分享的任何代碼告訴我們關於「它」的信息嗎? –
以簡單的英文描述查詢條件開始,你會發現它很難.... – Pleun
它幾乎看起來像兩個查詢是適當的解決方案這\ – TGH