Home > Back-end >  How to get all columns in final table after joining 2 tables
How to get all columns in final table after joining 2 tables

Time:11-08

I have 2 tables T1 and T2. I need to join based on gt and gcd. Both tables are having a column named gcd. How to modify the below query to get both gcd columns from 2 tables in the final table.

select T1.*
, NVL(T2.gcd,'U')::VARCHAR(1) AS gcd
FROM T1
LEFT JOIN TABLE2 T2 ON T2.gt=  T1.gcd

CodePudding user response:

The columns need to have different names. You either rename the second "gcd", which you are getting from T2, or rename both to new names.

select T1.*
, NVL(T2.gcd,'U')::VARCHAR(1) AS gcd_t2
FROM T1
LEFT JOIN TABLE2 T2 ON T2.gt=  T1.gcd
  • Related