使用另一个表中的列中的值更新表中某些特定项目中的列

发布于 2025-01-14 07:37:37 字数 1238 浏览 4 评论 0原文

我有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 技术交流群。

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

发布评论

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

评论(1

逐鹿 2025-01-21 07:37:37

UPDATE 语句中使用正确的连接,如下所示:

UPDATE table1 t1
INNER JOIN table2 t2 ON t2.id = t1.id
INNER JOIN table3 t3 ON t3.itemREF = t2.itemREF
SET t1.image = t3.local_image;

Use proper joins in the UPDATE statement like this:

UPDATE table1 t1
INNER JOIN table2 t2 ON t2.id = t1.id
INNER JOIN table3 t3 ON t3.itemREF = t2.itemREF
SET t1.image = t3.local_image;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文