Menus

Wednesday 1 February 2017

Update data From Other Table


Update one MySQL table with values from another



My customer table looks like:



And the customer_rate table looks like:



I want to update prize in customer with the id from customer_rate based on prize 
Action : customer.prize = customer.qty * customer_rate.prize
The updated table will hopefully look like:


I have a query that works

UPDATE customerINNER JOIN customer_rate ON (customer.cus_id = customer_rate.id)SET customer.prize = customer.qty * customer_rate.prize



add where condition 

UPDATE customerINNER JOIN customer_rate ON (customer.cus_id = customer_rate.id)SET customer.prize = customer.qty * customer_rate.prize where customer.id = 1




No comments:

Post a Comment