Home > Blockchain >  Left Join postgres SQL duplicate ON column
Left Join postgres SQL duplicate ON column

Time:01-20

I am doing a LEFT JOIN on a postgres table. As a result, in my final table appears a duplicate column, which is the column ON I have done the join. Why?

select *
from ltc_ts lt 
left join ltc_stock_metrics lsm 
on lt."index" =lsm."index"

PS: "index" is a column name for both tables I want to join

CodePudding user response:

The recommended solution is to not use select * but only select those columns that you really need.

If you want to stick with select * you can join with the using() clause instead. This will then return the index column only once.

select *
from ltc_ts lt 
  left join ltc_stock_metrics lsm using ("index")
  •  Tags:  
  • Related