7

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;
3

2 Answers 2

7

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Isn't product.price will refer to the old value of product_shop.price?
4

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

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.