在 mysql 中使用 IF 更新数据并在如果为 false 时定义“不做任何事情"

2022-01-17 00:00:00 sql-update sql if-statement mysql

我正在尝试使用 IF 查询来更新我的 mysql 表中的某些整行.众所周知,IF 查询有 3 个参数.您要查找的内容的第 1 部分,如果找到/为真,则为第 2 部分,如果未找到/为假,则为第 3 部分.我只希望它在它为真时更新,如果为假则什么也不做.如何定义不做任何事情"以使虚假部分不会被更新为其他任何内容?对不起,我的英语不好.并感谢您的帮助.

Im trying to use IF query in update some entire row in my mysql table. As known IF query have 3 parameters. Part 1 of what you looking for, part 2 if its found / true and part 3 if its not found / false. I just want it to be update when its true and doing nothing if false. How to define 'dont do anything' so the false part wont be update into anything else? Sorry for my bad english. And thanks for your help.

推荐答案

您可以在 FALSE 部分重新分配相同的列值以不执行任何操作.

You can reassign the same value of column in FALSE part to do nothing.

试试这个:

UPDATE tableA SET COL1 = IF(a=b, c, COL1)

相关文章