SQL - 使用另一个表的字段更新表 [英] SQL - Update a table using a field of another table

查看:64
本文介绍了SQL - 使用另一个表的字段更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下更新查询:

I am trying to execute the following update query:

UPDATE Commodities 
INNER JOIN UniqueCountries 
     ON Commodities.wbCode = UniqueCountries.wbCode 
SET Idenb = UniqueCountries.wbName||yr

查询显然是错误的,因为它不起作用.我该如何解决?

The query is clearly wrong, as it doesnt work. How can I fix it?

该查询应该使用 wbNameyr (wbName||yr代码>).但是,wbName 位于另一个名为 UniqueCountries 的表上,这就是我尝试执行内部联接的原因.

The query is supposed to update column IdenB with the concatenated value of wbName and yr (wbName||yr). However, wbName is on another table called UniqueCountries, which is why I tried to perform an Inner Join.

我做错了什么,我该如何解决?非常感谢.

What am I doing wrong and how can I fix it? Thank you very much.

推荐答案

我在中看不到任何指示UPDATE 语句中支持 FROMJOIN 的文档.

I can't see any indication in the docs that FROM or JOIN are supported in UPDATE statements.

如果没有,也许您可​​以尝试相关的子查询.

Maybe you could try a correlated sub query if not.

UPDATE Commodities  
SET Idenb = (SELECT UniqueCountries.wbName||yr 
             FROM UniqueCountries 
             WHERE Commodities.wbCode = UniqueCountries.wbCode)

这篇关于SQL - 使用另一个表的字段更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆