更新时间:2023-02-26 10:28:05
UPDATE messages
SET s_deleted = IF(sender = :sender, 1, s_deleted),
r_deleted = IF(recipient = :recipient, 1, r_deleted)
WHERE id = :id
如您所见,技巧"是在不满足条件时简单地将列设置为其现有值,以便仅在必要时更新.
As you can see, the "trick" is to simply set a column to its existing value when the criteria isn't met, so it only gets updated when necessary.