dreamend
dreamend

Reputation: 79

SQL Update - Adding to String to One Attribute

My mysql table is : Product (name,price,metaDescription)

I want to write an SQL UPDATE to Set my metaDescription name+' is only just for'+metaDescription

I tried this but it didn't work

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

Upvotes: 0

Views: 86

Answers (1)

mu is too short
mu is too short

Reputation: 434615

You should use the concat function:

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

MySQL should automatically convert price to a string type for you.

MySQL is trying to convert your strings to numbers (and silently failing) when you use +:

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

Upvotes: 1

Related Questions