mysql - Update table if conditions met. (update the value from table b to a) corresponding value required -
this question has answer here:
- match 2 sql columns if = update different column 1 3 answers
- how 3 table join in update query? 4 answers
i have table in have fields 'date', 'time', cost , order_id
table b has fields 'year' 'month' 'hour' 'cost' , order_id fields.
both tables linked "order_id" field. want update table if year, month, hour , order_id same in both tables , update corresponding value table b table field "cost"
i have used statement, query not working? wrong in it? need help
update item a, cost b set a.cost = b.cost a.order_id = b.order_id , year(a.date) = b.year , month(a.date) = b.month , hour(a.time) = b.hour
update item join cost b on a.order_id = b.order_id , year(a.date) = b.year , month(a.date) = b.month , hour(a.time) = b.hour set a.cost = b.cost
Comments
Post a Comment