简体   繁体   中英

SQL Query — update many records from 1 record in same table

We've got a table of places. The same place may occur multiple times in our table (bad design, not our choice). We had someone go through and find addresses for each of these places. They only updated one of the many instances of each place.

Here is a query that does NOT work, but I think shows what I am trying to do.

update places set address1 = places2.address1 
inner join places places2 ON places.placename = places2.placename 
where (places2.address1 <> '' AND places2.address1 is not null) 

Anyone want to give me a nudge in the right direction?

update places set address1 = places2.address1 
from places inner join places places2 ON places.placename = places2.placename 
where (places2.address1 <> '' AND places2.address1 is not null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM