Querying the inner join of two tables with the same column name, Column 'exName' in field list is ambiguous

Ben Pearce picture Ben Pearce · Feb 23, 2013 · Viewed 70k times · Source

I am querying the inner join of three tables using the following query.

Two of the tables have columns named "name1". I am getting the following error.

Column 'exName' in field list is ambiguous

The "name1" columns are foreign key so the information should be identical. Can anyone suggest a compact way around this?

$result = mysql_query("SELECT name1,name2,name3 FROM `table1` INNER JOIN `table2` ON table2.name1=table1.PrimaryKey INNER JOIN `table3` ON table3.name1=table1.PrimaryKey"); 

Answer

Vincent Ramdhanie picture Vincent Ramdhanie · Feb 23, 2013

You need to qualify your column names with the table names.

 SELECT table1.name1, table2.name1, etc.