Michael Corleone
Michael Corleone

Reputation: 105

Do some calculations of the values from two table and store it in one of the table

First Table Name: table1

| email           | value  |
----------------------------
| [email protected]   |0.12      |
| [email protected]   |0.23      |
| rthgmail.com    | 0.45     |
| [email protected]   |0.56      |
| [email protected]   | 0.78     |
| [email protected]   | 0.35     |

Second Table Name: table2

| email           | result |
----------------------------
| [email protected]   |0.3      |
| [email protected]   |0.6      |
| rthgmail.com    | 0.7     |
| [email protected]   |0.8      |
| [email protected]   | 0.1     |
| [email protected]   | 0.3     |

Now, I want to perform this mathematical operation

value(table1) = result(table2)+value(table1) /2

for email="[email protected]"

I want to use the UPDATE query.

Thank you!!!

Upvotes: 0

Views: 21

Answers (1)

Vasfed
Vasfed

Reputation: 18494

You can join tables in update the same way you do in a select:

UPDATE table1
JOIN table2 ON table1.email=table2.email
SET table1.value = (table2.result + table1.value) / 2
WHERE table1.email = "[email protected]"

Upvotes: 1

Related Questions