简体   繁体   中英

How do I add specific columns from different tables onto an existing table in postgresql?

I have an original table (TABLE 1):

A B C D
1 3 5 7
2 4 6 8

I want to add column F from the table below (Table 2) onto table 1:

A F G H
1 29 5 7
2 30 6 8

As well as adding Column J,L and O from the table below (Table 3) onto column 1:

A I J K L M N O
1 9 11 13 15 17 19 21
2 10 12 14 16 18 20 22

How do I go about adding only the specific columns onto table 1?

Expected Result:

A B C D F J L O
1 3 5 7 29 11 15 21
2 4 6 8 30 12 16 22

Use following query

SELECT T1.A,
       B,
       C,
       D,
       F,
       J,
       L,
       O
FROM   table1 T1
       JOIN table2 T2
         ON T1.A = T2.A
       JOIN table3 t3
         ON T1.A = T3.A  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM