In case you don't have the value in one column but instead had to calculate it from the other table (in this example price_per_vehicle
from shipments_shipment
).Then assuming that shipments_shipment
has price
and vehicle_id
columns the update for a specific vehicle could look like this:
-- Specific vehicle in this example is with id = 5WITH prices AS ( SELECT SUM(COALESCE(s.price, 0)) AS price_per_vehicle FROM shipments_shipment AS s WHERE s.vehicle_id = 5)UPDATE vehicles_vehicle AS vSET v.price = prices.price_per_vehicleFROM pricesWHERE v.id = 5