2011-06-27 38 views
0

我的MySQL表:产品(名称,价格,metaDescription)SQL更新 - 添加到字符串到一个属性

我想写一个SQL UPDATE设置我的metaDescription名+“才刚刚为” + metaDescription

我试过,但没有奏效

UPDATE 
    product 
SET 
    metaDescription=name+' is just for'+price; 

回答

1

您应该使用concat function

update product 
set metaDescription = concat(name, ' is just for ', price); 

MySQL应该自动将price转换为字符串类型。

MySQL正在尝试将字符串转换为数字(默默失败)当您使用+

mysql> select 'this' + 'that'; 
+-----------------+ 
| 'this' + 'that' | 
+-----------------+ 
|    0 | 
+-----------------+ 
+0

你说得对。我没有注意到它是关于MySQL的 – heximal