4mla1fn
4mla1fn

Reputation: 303

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

Upvotes: 0

Views: 58

Answers (1)

EJ Egyed
EJ Egyed

Reputation: 6084

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;

Upvotes: 2

Related Questions