Skip to content
Advertisement

(SQL) How do I differentiate 2 columns from different tables with the same name when selecting?

I’m using an Oracle 12c SQL server. The goal is to create a view containing each company and the drugs it produces.

How can I differentiate two columns with the exact same name but located in different tables using SELECT? All relevant code below, including results with error.

I understand why I might be getting a duplicate name error as they both have the same header “name”, but thought I handled it by identifying the table beforehand (i.e. pc.name and dg.name). Help!

SQL Tables Being Joined:

enter image description here

SQL Column Naming Error:

enter image description here

Advertisement

Answer

You have ambiguous column names in output from your view:

pc.name, dg.name

Adding alias for columns should solve this:

pc.name as pc_name, dg.name as dg_name
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement