Home > Software design >  SQL - how to rename column being used on inner join
SQL - how to rename column being used on inner join

Time:10-15

I have created a view in Microsoft SQL Server Management Studio, and I now want to join it to the correct spatial information.

I have created the query below

select * from v_postal_address_view pa
INNER JOIN SPATIAL_INFO sp ON sp.ECAD_ID = pa.BUILDING_ID

This runs fine as the ECAD_ID and BUILDING_ID are linked. However, I now want to save my results as a new view but cannot because the v_postal_address_view contains ECAD_ID already, therefore forbidding the SPATIAL_INFO tables ECAD_ID to be joined as the name is not unique.

How can I rename the ECAD_ID column in spatial_info during the inner join to the view??

CodePudding user response:

CREATE VIEW RESOLVE_AMBIGUOUS_NAMES AS
    SELECT T1.id AS id_1,
           T2.id AS id_2
      FROM TABLE_1 T1
     INNER
      JOIN TABLE_2 T2
        ON T1.fk = T2.pk
  • Related