SQL查询 - 从同一个表中的1条记录更新许多记录

时间:2023-01-20 15:41:55

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?

有人想给我一个正确方向的推动吗?

1 个解决方案

#1


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)

#1


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)