Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql change all values in a column

Tags:

sql

mysql

I want to change all values in the tablecolumn "Quellendatum".

When the row-value is 2005-06-20 then it should be replaced with 2012-06-20. When the row-value is NULL or empty, then it should be untouched.

Currently i modify this manually by selecting the row:

UPDATE  `outgoing2`.`tbl_hochschule`  SET  `Quellendatum` =  '2012-06-20'  WHERE  `tbl_hochschule`.`id` =1; 

Is there a way to automate this task?

like image 462
StandardNerd Avatar asked Mar 15 '13 10:03

StandardNerd


People also ask

How do I UPDATE all values in a column in MySQL?

To set all values in a single column MySQL query, you can use UPDATE command. The syntax is as follows. update yourTableName set yourColumnName =yourValue; To understand the above syntax, let us create a table.

How do I UPDATE multiple values in one column in MySQL?

MySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.


2 Answers

How about:

UPDATE outgoing2.tbl_hochschule  SET Quellendatum = '2012-06-20'  WHERE Quellendatum = '2005-06-20'  AND !isnull( Quellendatum ); 
like image 113
ethrbunny Avatar answered Sep 23 '22 18:09

ethrbunny


In MySql you can do:

UPDATE TABLENAME     SET IDCOLUMN=VALUE     WHERE IDCOLUMN=VALUE     AND !isnull (IDCOLUMN) 
like image 39
LucianoDemuru Avatar answered Sep 22 '22 18:09

LucianoDemuru