venkat reddy padala
venkat reddy padala

Reputation: 553

How to append a value to an existing column in mysql which can contain null or a String?

in my table a column selected contains default value null, but i want to update the column by appending a string to it with a condition that if the field contains null then it should be updated else if it contains any other string then i need to update it like update tabname set colname=concat(colname,',newString')? any information would be a great help for me thanks in advance...

Upvotes: 2

Views: 1112

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64466

You can use case

 update tabname
 set colname= case when colname is null or colname =''
              then 'newString'
              else concat(colname,'newString')
              end

Upvotes: 5

Related Questions