Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL concatenate a string to a column

Tags:

mysql

What I'm trying to do its edit the information from a row adding more data, for example:

select name, obs from users where area='it'

It gives me:

name       obs
charles    vegetarian
xena       otaku

and I want to add to the their obs 'friendly hard worker'

I have tried:

update users set obs=obs+' frienly hard worker' where area='it'

but it didn't work, the result that I want is:

name       obs
charles    vegetarian frienly hard worker
xena       otaku frienly hard worker
like image 325
user1920062 Avatar asked Jan 11 '13 16:01

user1920062


2 Answers

In MySQL, the plus sign + is an operand for performing arithmetic operations.

You need to use the CONCAT() function to concatenate strings together.

UPDATE users 
SET obs = CONCAT(obs,' frienly hard worker') 
WHERE area='it';
like image 80
Blaise Swanwick Avatar answered Oct 06 '22 23:10

Blaise Swanwick


update users set obs= CONCAT('string1', column1 , 'string2', column1 , 'string3' ) where area='it'
like image 27
Ali Elsayed Salem Avatar answered Oct 06 '22 23:10

Ali Elsayed Salem