corycorycory
corycorycory

Reputation: 1656

Best way to add and populate new column with data from second table

I have two tables.

Table A is a list of invoices each with a unique invoice ID.

Table B is a list of invoice attributes with a unique invoice ID that corresponds to those in Table A.

I want to add a new column to table A called "Contact Name" by looking up that value by invoice ID in table B.

I know I could create a temp table by joining TableA and TableB, and then replace the existing table with that new one... but I'm curious if there is a better way to do this.

Upvotes: 1

Views: 4738

Answers (1)

Simimmo
Simimmo

Reputation: 668

alter table A add CONTACT_NAME VARCHAR2(50);

update A 
set contact_name = (select value from B where B.invoice_id = A.invoice_id);

Upvotes: 5

Related Questions