我有 3 張桌子。我想Image用表 3 中的本地影像更新表 1 中的所有行。
表 1 按 ID 與表 2 相似。表 2 和表 3 由 鏈接itemRef。
作為我想要的示例:表 1 中的 ID 1 獲取影像 A。因為表 1 中的 IDitemRef = 14在表 2 中,而itemRef = 14表 3 中具有影像 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
你能幫我做這個嗎?
uj5u.com熱心網友回復:
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;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/443639.html
下一篇:查找具有特定條件的SQL重復項
