基于ID对应更新表

时间:2022-11-25 12:08:13

I need to copy data from one table (A) to another (B) based on id correspondence, but the correspondence of ID is actually stored into a third table (C). So the table with the correspondence looks like

我需要根据id对应关系将数据从一个表(A)复制到另一个表(B),但ID的对应关系实际上存储在第三个表(C)中。所以带有对应关系的表看起来像

C.A_ID  C.B_ID
1       33
2       56
3       74

I tried something like

我尝试过类似的东西

UPDATE DB.A 
SET DB.A = DB.B
FROM DB.A p
INNER JOIN 
    DB.B p1
INNER JOIN
    DB.C p2

how to insert the ID correspondence?

如何插入ID对应?

2 个解决方案

#1


0  

UPDATE A , (select c.id1, b.data from B join C on (B.id2 = C.id2 )) as Foo
SET A.data = Foo.data
WHERE
A.id1 = Foo.id1

#2


0  

you need to use select into statement for selecting data from one table and insert in another table.

您需要使用select into语句从一个表中选择数据并插入另一个表中。

#1


0  

UPDATE A , (select c.id1, b.data from B join C on (B.id2 = C.id2 )) as Foo
SET A.data = Foo.data
WHERE
A.id1 = Foo.id1

#2


0  

you need to use select into statement for selecting data from one table and insert in another table.

您需要使用select into语句从一个表中选择数据并插入另一个表中。