Reputation: 2917
I have a table foo:
Id col1 col2 result
-- ---- ---- -----
1 a b
2 c d
I need to update row with id 1 like this:
update foo set result = 'str1=x,str2=col2_value' where Id = 2
result after update must be:
Id col1 col2 result
-- ---- ---- ----------
1 a b str1=x,str2=b
2 c d
How to put value of col2 to the string in result?
Upvotes: 0
Views: 147
Reputation: 4192
UPDATE foo SET result = 'str1=x,str2 ='+col2+'' FROM foo WHERE id = 1;
Upvotes: 0
Reputation: 1086
Sounds like you need the concat function:
UPDATE foo SET result = CONCAT('str1=x,str2=',col2) WHERE id = 1;
Upvotes: 0
Reputation: 3241
Just use Concat
update foo set result=CONCAT('str1=x,str2=',col2) where Id=1
Upvotes: 1