Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: update single table one column data to another column

Tags:

sql

mysql

I have a MySQL table called Cars. The Cars table has three columns: 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.

like image 622
randombits Avatar asked Feb 19 '12 04:02

randombits


1 Answers

update cars set
bar = foo
where foo is not null
like image 83
Bohemian Avatar answered Oct 03 '22 16:10

Bohemian