简体   繁体   English

MySQL:将单个表的一列数据更新到另一列

[英]MySQL: update single table one column data to another column

I have a MySQL table called Cars . 我有一个名为Cars的MySQL表。 The Cars table has three columns: id int auto increment , foo varchar(255) , bar varchar(255) . Cars表有三列: id int auto incrementfoo varchar(255)bar varchar(255)

I want to simply update all rows in the Cars table into the bar column with the same value from foo if foo is not null. 我想简单地在汽车表中的所有行更新到bar与来自相同的值列foo ,如果foo不为空。 So both foo and bar will have the same value after the update wherever foo is not null. 因此,在foo不为null的情况下,foo和bar将在更新后具有相同的值。

update cars set
bar = foo
where foo is not null
UPDATE cars SET bar = foo WHERE foo IS NOT null

更新查询将是:

 UPDATE Cars set bar = foo where foo is not null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM