SupaMonkey
SupaMonkey

Reputation: 884

MySQL Update Multiple Fields with Same Value

I have two fields in two seperate tables that need to be updated to the same value. Without procedures, etc. Is this possible in a single query?

Working statement:

UPDATE product,product_shop SET
 product_shop.price='737.96',
 product.price='737.96',
 product_shop.wholesale_price='479.67',
 product.wholesale_price='479.67'
WHERE 
 product_shop.id_product=product.id_product AND
 product_shop.id_product=14;

What I was hoping for:

UPDATE product,product_shop SET
 product_shop.price=product.price='737.96',
 product_shop.wholesale_price=product.wholesale_price='479.67'
WHERE 
 product_shop.id_product=product.id_product AND
 product_shop.id_product=14;

Upvotes: 7

Views: 13417

Answers (2)

jfxninja
jfxninja

Reputation: 381

MySQL docs state you can do this, if you are trying to avoid printing the value twice you could do the following:

UPDATE product,product_shop SET
 product_shop.price='737.96',
 product.price=product_shop.price, 
 product_shop.wholesale_price='479.67',
 product.wholesale_price=product_shop.wholesale_price
WHERE 
 product_shop.id_product=product.id_product AND
 product_shop.id_product=14;

Upvotes: 7

d'alar'cop
d'alar'cop

Reputation: 2365

No. Your "working query" is the best you can do.

Upvotes: 4

Related Questions