Is it possible to do an UPDATE query in MySQL which updates field value only if certain condition is met? Something like this:
UPDATE test
SET
CASE
WHEN true
THEN field = 1
END
WHERE id = 123
In other words:
UPDATE test
SET
something = 1, /*field that always gets updated*/
CASE
WHEN true
THEN field = 1 /*field that should only get updated when condition is met*/
END
WHERE id = 123
What is the proper way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…