select sum(amount) as amount from table2 group by query
update table1 left join (select query, sum(amount) as amount from table2 group by query) as t2 using(query) set table1.amount = ifnull(t2.amount, 0 /*значение по-умолчанию, если в table2 таких query нет ни одного*/)