使用另一个表中的列中的值更新表中某些特定项目中的列
我有3张桌子。我想使用表 3 中的本地图像更新表 1 中的所有 Image
行。
表 1 与表 2 的 ID 相似。表 2 和表 3 通过 itemRef
链接。
作为我想要的示例:表 1 中的 ID 1 获取图像 A。因为表 1 中的 ID 是表 2 中的 itemRef = 14
,并且 itemRef = 14
表 3 中的 code> 有图像 A。
╔════╦═══════╗
║ ID ║ Image ║
║ 1 ║ ║
║ 2 ║ ║
║ 3 ║ ║
║ 4 ║ ║
║ 5 ║ ║
║ 6 ║ ║
║ 7 ║ ║
║ 8 ║ ║
╚════╩═══════╝
╔════╦═════════╗
║ ID ║ ItemREF ║
║ 1 ║ 14 ║
║ 2 ║ 15 ║
║ 3 ║ 16 ║
║ 4 ║ 17 ║
║ 5 ║ 18 ║
║ 6 ║ 19 ║
║ 7 ║ 20 ║
║ 8 ║ 21 ║
╚════╩═════════╝
╔═════════╦═════════════╗
║ ItemREF ║ Local Image ║
║ 14 ║ A ║
║ 15 ║ B ║
║ 16 ║ C ║
║ 17 ║ D ║
║ 18 ║ E ║
║ 19 ║ F ║
║ 20 ║ G ║
║ 21 ║ H ║
╚═════════╩═════════════╝
这是我到目前为止所尝试过的:
update table1
set table1.image = table3.local_image
where table1.id in (select table3.local_image
from table1, table2, table3
where table1.id = table2.id
and table2.itemREF = table3.itemREF
你能帮我做这个吗?
I have 3 tables. I want to update all Image
rows from table 1, with local image from table 3.
Table 1 is liked with table 2 by ID. Table 2 and 3 are linked by itemRef
.
As an example of what I want: is that ID 1 from table 1, gets image A. Because ID from table 1, is itemRef = 14
in table 2, and itemRef = 14
in table 3 has image A.
╔════╦═══════╗
║ ID ║ Image ║
║ 1 ║ ║
║ 2 ║ ║
║ 3 ║ ║
║ 4 ║ ║
║ 5 ║ ║
║ 6 ║ ║
║ 7 ║ ║
║ 8 ║ ║
╚════╩═══════╝
╔════╦═════════╗
║ ID ║ ItemREF ║
║ 1 ║ 14 ║
║ 2 ║ 15 ║
║ 3 ║ 16 ║
║ 4 ║ 17 ║
║ 5 ║ 18 ║
║ 6 ║ 19 ║
║ 7 ║ 20 ║
║ 8 ║ 21 ║
╚════╩═════════╝
╔═════════╦═════════════╗
║ ItemREF ║ Local Image ║
║ 14 ║ A ║
║ 15 ║ B ║
║ 16 ║ C ║
║ 17 ║ D ║
║ 18 ║ E ║
║ 19 ║ F ║
║ 20 ║ G ║
║ 21 ║ H ║
╚═════════╩═════════════╝
This is what I've tried so far:
update table1
set table1.image = table3.local_image
where table1.id in (select table3.local_image
from table1, table2, table3
where table1.id = table2.id
and table2.itemREF = table3.itemREF
Can you help me to make this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
UPDATE
语句中使用正确的连接,如下所示:Use proper joins in the
UPDATE
statement like this: