Oracle SQL: Update a table with data from another table

后端 未结 7 2155
广开言路
广开言路 2020-11-22 02:01

Table 1:

id    name    desc
-----------------------
1     a       abc
2     b       def
3     c       adf

Table 2:

id    na         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 02:11

    try

    UPDATE Table1 T1 SET
    T1.name = (SELECT T2.name FROM Table2 T2 WHERE T2.id = T1.id),
    T1.desc = (SELECT T2.desc FROM Table2 T2 WHERE T2.id = T1.id)
    WHERE T1.id IN (SELECT T2.id FROM Table2 T2 WHERE T2.id = T1.id);
    

提交回复
热议问题