Oracle SQL: Update a table with data from another table

Highly active question. You have enough reputation to answer this question. The reputation requirement helps protect this question from spam and non-answer activity. Learn more. Solution Source: Oracle SQL: Update a table with data from another table – Stack Overflow

Highly active question. You have enough reputation to answer this question. The reputation requirement helps protect this question from spam and non-answer activity. Learn more. Solution Source: Oracle SQL: Update a table with data from another table – Stack Overflow

Highly active question. You have enough reputation to answer this question. The reputation requirement helps protect this question from spam and non-answer activity. Learn more.

Table 1:

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

Table 2:

id    name    desc
-----------------------
1     x       123
2     y       345

Solution

UPDATE table1 t1
   SET (name, desc) = (SELECT t2.name, t2.desc
                         FROM table2 t2
                        WHERE t1.id = t2.id)
 WHERE EXISTS (
    SELECT 1
      FROM table2 t2
     WHERE t1.id = t2.id )
UPDATE (SELECT t1.id, 
               t1.name name1,
               t1.desc desc1,
               t2.name name2,
               t2.desc desc2
          FROM table1 t1,
               table2 t2
         WHERE t1.id = t2.id)
   SET name1 = name2,
       desc1 = desc2

Source: Oracle SQL: Update a table with data from another table – Stack Overflow

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments