Hi,
I would like know how to update records in a table with data from another table. Is it possible to do a join or to make a sub-query ?
With the data below (example), I would to update the City field in the UserTable with the City from the LocationTable. Both table have a relationship; CITY_CODE
Now, if you look at my query below, you'll that it's wrong, but it's logically what I want to achieve.
Thanks in advance.
I would like know how to update records in a table with data from another table. Is it possible to do a join or to make a sub-query ?
With the data below (example), I would to update the City field in the UserTable with the City from the LocationTable. Both table have a relationship; CITY_CODE
Now, if you look at my query below, you'll that it's wrong, but it's logically what I want to achieve.
Code:
__UserTable__
ID ! NAME ! CITY ! CITY_CODE !
243 ! Jeremy Lingo ! Seattllez ! S034 !
655 ! Bobby Bouche ! Portland ! P001 !
Code:
__LocationTable__
ID ! CITY ! CITY_CODE !
9920 ! Portland ! P001 !
2332 ! Seattle ! S034 !
2299 ! New York ! N202 !
Code:
UPDATE UserTable UsrTbl
SET CITY = ( select CITY
from LocationTable LocTbl
where UsrTbl.CITY_CODE = LocTbl.CITY_CODE
and UsrTbl.CITYCODE = 'S034'
)
Thanks in advance.