Reputation: 661
I am having two tables .
Table1 , Table2.
Table1 has name, age, salary.
Table2 has name,height, weight,Relevance,Weight_po etc.
. Both the tables has name as primary key. Now I want to insert a two more new column in table 1 ie height, weight. The values for height and weight has to fetch from Table2 where table1.name matches with table2.name.
Help me how to achieve this in postgres.
Upvotes: 0
Views: 129
Reputation: 301
Have you created height and weight columns in Table 1?
This will help to populate the values:
UPDATE Table1 t1
SET height= t2.height,weight=t2.weight
FROM Table2 t2
WHERE t1.name= t2.name
Tell me how it goes
Upvotes: 0
Reputation: 14389
You can use select into statement and insert all data you want onto a NewTable with the structure you describe:
EDIT: Based on comment
Create table NewTable as
SELECT Table1.name,age,salary,height,weight
INNER JOIN Table2
ON Table1.name=Table2.name
Upvotes: 0