Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update concat text with null value in mysql

Tags:

mysql

trasaction table description field have some value it is worked fine. description feild default value is NULL,its not works..

update transaction set domain='hiox.com',description=CONACT(description,',domain swapped from hioxindia.com to hiox.com') where id=23602

help me..

like image 439
Vaishu Avatar asked Jun 25 '12 10:06

Vaishu


People also ask

How to handle NULL in CONCAT?

When you concatenate any string with a NULL value, it will result in NULL. To avoid this, you can use the COALESCE function. The COALESCE function returns the first non-Null value. So, when there is a value in the column that is not null, that will be concatenated.

Can we use concat in update query MySQL?

We can append a string of data to an existing data of a field by using concat function of MySQL. Here we are not updating or replacing existing data with a new one, we are just adding the string at the end(or at the beginning ) of the field data. Joining strings by using CONCAT and handling NULL value.

How do you concatenate in a update query?

MySQL, UPDATE data into a database using CONCAT() If you would like the data that you are entering to appear at the beginning of the existing data, simply flip the concatenation, example: UPDATE table1 SET changelog = CONCAT("new data", changelog) WHERE id = 'idnumber';


1 Answers

Use ifnull():

update `transaction` 
   set domain='hiox.com',
   description=CONCAT(ifnull(description, ''), ',domain swapped from hioxindia.com to hiox.com') 
where id=23602

Documentation

like image 197
juergen d Avatar answered Oct 30 '22 05:10

juergen d