Q:

UPDATE with SELECT WHERE NULL

i have sql query select literally like this
SELECT ad.* from (
SELECT idpresen, presenloc.satkerid, lat, lng, LATITUDE as lat_kantor, LONGITUDE as lng_kantor, (6371000 * ACOS(COS(RADIANS(lat)) * COS(RADIANS(LATITUDE)) * COS(RADIANS(LONGITUDE) - RADIANS(lng)) + SIN(RADIANS(lat)) * SIN(RADIANS(LATITUDE)))) as jarak
FROM presenloc
CROSS JOIN koordinat ON presenloc.satkerid LIKE CONCAT(koordinat.satkerid, '%')
) as ad
inner join ( 
SELECT idpresen, min(6371000 * ACOS(COS(RADIANS(lat)) * COS(RADIANS(LATITUDE)) * COS(RADIANS(LONGITUDE) - RADIANS(lng)) + SIN(RADIANS(lat)) * SIN(RADIANS(LATITUDE)))) as jarak
FROM presenloc 
LEFT JOIN koordinat ON presenloc.satkerid LIKE CONCAT(koordinat.satkerid, '%')
group by idpresen,presenloc.satkerid
 ) as f
 on ad.idpresen = f.idpresen and ad.jarak = f.jarak

actually i want to update data in presenloc table.
The column that i want to update is lat_kantor, lng_kantor, and jarak based on that select and i want to update data where whether lat_kantor, lng_kantor, or jarak is null

A:

Directly:
UPDATE table_to_update
  JOIN ( your long query ) AS data_for_update USING (PK_column)
SET table_to_update.column1 = data_for_update.column1,
 -- ...
    table_to_update.columnN = data_for_update.columnN
WHERE table_to_update.column1 IS NULL
   -- ...
   OR table_to_update.columnN IS NULL

