I am having trouble writing a sql query and I was hoping that someone may be able to help me out.
Here’s what I want my query to do:
- Take the “prod_value” column from the “product” table
- Multiply a constant (assume the number 2) times the “worth” column on the “value” table that corresponds to the one-to-one relationship between value <-> product.
- Update the “prod_value” column in the “product” table to the new updated value.
For example…
Here’s the tables:
value
id | worth | product_id |
1 | 10 | 1 |
product (before)
id | name | prod_value |
1 | product1 | 100 |
and assume constant = 2.
Then what I want after I run the query is the following:
product (after)
id | name | prod_value |
1 | product1 | 120 |
The 120 comes from 100 (previous value) + 2*10
I was hoping to have this done with one single query, is this even possible?
If anyone can help me I would be very grateful!
Thanks 🙂
1 Answer