在 mysql 中使用 IF 更新数据并在如果为 false 时定义“不做任何事情" [英] Update data using IF in mysql and define 'dont do anything' when if false

查看:31
本文介绍了在 mysql 中使用 IF 更新数据并在如果为 false 时定义“不做任何事情"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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)

这篇关于在 mysql 中使用 IF 更新数据并在如果为 false 时定义“不做任何事情"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆