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

发布于 2024-07-23 00:30:08 字数 374 浏览 4 评论 0原文

我们有一张位置表。 同一个地方可能会在我们的表中出现多次(糟糕的设计,不是我们的选择)。 我们派人仔细检查并找到每个地方的地址。 他们只更新了每个地点的众多实例之一。

这是一个不起作用的查询,但我认为显示了我正在尝试做的事情。

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

有人想推动我朝正确的方向前进吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生死何惧 2024-07-30 00:30:08
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)
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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文