MySQL 将字符串连接到列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14282369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL concatenate a string to a column
提问by user1920062
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'
我想添加到他们的 obs '友好的努力工作者'
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
回答by Blaise Swanwick
In MySQL, the plus sign +
is an operand for performing arithmetic operations.
在 MySQL 中,加号+
是执行算术运算的操作数。
You need to use the CONCAT()
function to concatenate strings together.
您需要使用该CONCAT()
函数将字符串连接在一起。
UPDATE users
SET obs = CONCAT(obs,' frienly hard worker')
WHERE area='it';
回答by Ali Elsayed Salem
update users set obs= CONCAT('string1', column1 , 'string2', column1 , 'string3' ) where area='it'