Home > Software engineering >  Merge 2 PostgreSQL tables
Merge 2 PostgreSQL tables

Time:11-06

I have two tables:

table1 has attributes: Price, Name (IS)
table2 has attribute: Price, Name (IS)

I would like to update the table1 Price entries with the price entries in table2 when table1.Name (IS)= table2.Name (IS)

UPDATE table1
SET Price= table2.Price
FROM table2
WHERE table2.Name (IS)= table1.Name (IS)

Column does not exist error

CodePudding user response:

I think you are missing a SELECT:

UPDATE table1
SET Price= (SELECT table2.Price
FROM table2
WHERE table2.Name = table1.Name)

CodePudding user response:

If you use special characters in column name need append column name between double-quotes, like bellow sample:

UPDATE table1
SET "Price" = table2."Price"
FROM table2
WHERE table2."Name (IS)" = table1."Name (IS)"
  • Related