mysql - SQL help - Updating a field in one table to match a field in another table based on matching a different field -
appreciate help. i'm working on db designed bit poorly. need fix bad data updating 1 table based on follows (i loosely describing sql need):
two tables:
airports- includes fields:lat,lon,airport_id.events- includes fields:lat,lon,airport_id.
i want update (currently incorrect) events table lat , lon (correct) airports table lat , lon.
basically: update events <events.airport_id = airports.airport_id> set events.lat = airports.lat
then can run again lon.
i know i'm close, not there exact syntax.
thanks!
this should work:
update events e set e.lat = (select a.lat airports a.airport_id = e.airport_id), e.lon = (select a.lon airports a.airport_id = e.airport_id) ;
Comments
Post a Comment