5

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;
SupaMonkey
  • 718
  • 8
  • 23

2 Answers2

5

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;
jfxninja
  • 313
  • 3
  • 11
2

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

d'alar'cop
  • 2,337
  • 1
  • 13
  • 18