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

时间:2022-09-21 15:56:24

I have a MySQL table called Cars. The Cars table has three columns: id int auto increment, foo varchar(255), bar varchar(255).

我有一个名为Cars的MySQL表。 Cars表有三列:id int auto increment,foo 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. So both foo and bar will have the same value after the update wherever foo is not null.

如果foo不为null,我想简单地将Cars表中的所有行更新为foo中具有相同值的bar列。因此,在foo不为null的情况下,foo和bar将在更新后具有相同的值。

3 个解决方案

#1


9  

update cars set
bar = foo
where foo is not null

#2


0  

UPDATE cars SET bar = foo WHERE foo IS NOT null

#3


0  

The update query would be:

更新查询将是:

 UPDATE Cars set bar = foo where foo is not null

#1


9  

update cars set
bar = foo
where foo is not null

#2


0  

UPDATE cars SET bar = foo WHERE foo IS NOT null

#3


0  

The update query would be:

更新查询将是:

 UPDATE Cars set bar = foo where foo is not null