Daniel Lawton
Daniel Lawton

Reputation: 466

Error Code: 1060. Not unique table/alias: `table1`

I have researched this issue but I haven't seen it explained very well yet and I want to try get a better understanding of the issue rather than blindly fixing it.

I'm trying to create a new table that is created from a left outer join.

CREATE TABLE `JoinTable` as
SELECT Col1, Col2 
FROM Table1, Table2
LEFT OUTER JOIN Table2
on Table1.Col1 = Table2.Col1;

Could someone please explain why this comes up with the error: Error Code: 1060. Not unique table/alias: table1

Thank you, Daniel

Upvotes: 1

Views: 49

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

Remove , Table2 in from clause

CREATE TABLE `JoinTable` as
SELECT Col1, Col2 
FROM Table1
LEFT OUTER JOIN Table2
on Table1.Col1 = Table2.Col1;

and for ambiguity you must esplicit the table name eg:

CREATE TABLE `JoinTable` as
SELECT table1.Col1, table2.Col2 
FROM Table1
LEFT OUTER JOIN Table2
on Table1.Col1 = Table2.Col1;

Upvotes: 2

Related Questions