Update data using IF in mysql and define #39;dont do anything#39; when if false(在 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 时定义“不做任何事情"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 mysql 中使用 IF 更新数据并在如果为 false 时定义“不做任何事情"
基础教程推荐
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
