update MaterialEntry set totalprice = (select sum(cost*amount) from MaterialEntryItem where materialEntry_id=MaterialEntry.id) where totalPrice is null; update foreigntousseapplication set suppliername = (select min(i.suppliername) from invoiceplan p,tousseitem i where p.id = i.recyclingapplication_id and foreigntousseapplication.id = p.id);