Search code examples
oracleoracle-sqldeveloper

how to add a column from one table to another


in have two oracle tables, as below. they have the same index column. (in my actual application, my master table has 30M rows and ~100 columns). what's the easiest way to add the "feat4" column of the feature 4 table to the master table? is there way to do this in sqldeveloper (other than writing sql)? thanks!

a master table with 7 rows and 4 columns, a new feature table with 7 rows and one column, and a new master table with 7 rows and now 5 columns


Solution

  • SQL Developer does not have functionality to do what you are describing, but it can be done using an ALTER TABLE and MERGE statement.

    ALTER TABLE master_table
        ADD feat4 VARCHAR2 (3); --Should be whatever datatype is in the feature_4_table
    
    MERGE INTO master_table m
         USING (SELECT id, feat4 FROM feature_4_table) f
            ON (m.id = f.id)
    WHEN MATCHED
    THEN
        UPDATE SET m.feat4 = f.feat4;