Common SQL Errors

MySQL Error 1066 ER_NONUNIQ_TABLE: Not unique table/alias - How to Fix and Prevent

Galaxy Team
August 5, 2025

MySQL throws ER_NONUNIQ_TABLE (Error 1066) when the same table name or alias appears more than once in a querys FROM or JOIN clause.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1066 ER_NONUNIQ_TABLE?

MySQL Error 1066: ER_NONUNIQ_TABLE signals duplicate table names or aliases in the FROM clause. Remove the duplicate reference or rename the conflicting alias to fix the issue.

Error Highlights

Typical Error Message

Not unique table/alias: '%s'

Error Type

Syntax Error

Language

MySQL

Symbol

ER_NONUNIQ_TABLE

Error Code

1066

SQL State

Explanation

Table of Contents

What is MySQL Error 1066 ER_NONUNIQ_TABLE?

Error 1066 occurs when MySQL encounters two identical table names or aliases in a single query block. The parser cannot unambiguously determine which table to reference, so execution stops with ER_NONUNIQ_TABLE.

The error typically appears in SELECT statements that join the same table twice, in subqueries with overlapping aliases, or in UPDATE/DELETE statements using JOIN syntax.

Resolving the conflict immediately restores query execution.

What Causes This Error?

Duplicate table aliases inside the same scope trigger the error first. When two tables share the same alias, MySQL cannot map column references unambiguously.

Using the same physical table twice in the FROM clause without an alias also causes a clash.

MySQL treats the unaliased table name as its own alias, so the second occurrence is not unique.

How to Fix MySQL Error 1066 ER_NONUNIQ_TABLE

Identify the duplicated name by looking at the error line. Rename one of the aliases or fully qualify the table with a unique alias. Alternatively, restructure the query with common table expressions (CTEs) to isolate scopes.

After renaming, rerun the query to confirm resolution.

Add the alias change to version control or Galaxys endorsed query library to prevent regressions.

Common Scenarios and Solutions

Self-join queries often reuse the same table name. Assign aliases like t1 and t2 to differentiate the two copies. Subqueries that reference the outer querys tables need unique aliases as well.

UPDATE statements with JOIN mistakenly omitting an alias on the target table can collide with the join table.

Always alias both tables clearly.

Best Practices to Avoid This Error

Adopt a consistent aliasing convention: short prefixes plus numerals (e.g., u1, u2) for multiple uses of the same table. Enforce this rule with code reviews in Galaxy Collections.

Enable MySQLs sql_require_primary_key or use Galaxys linting to highlight duplicate aliases during editing, catching the problem before execution.

Related Errors and Solutions

Error 1052 (ER_NONUNIQ): column repeats across joined tables.

Prefix columns with their table alias to resolve.

Error 1093 (ER_UPDATE_TABLE_IS_REFERENCED): updating a table that is also read in the same query. Use a derived table or subquery to separate reads and writes.

.

Common Causes

Duplicate alias in JOIN

Using the same alias for two joins on the same or different tables makes the alias non-unique.

Same table listed twice without alias

Repeating a table name in the FROM list without giving each occurrence a unique alias causes a clash.

Subquery reuses outer alias

An inner subquery that assigns an alias already used by the outer query raises ER_NONUNIQ_TABLE.

UPDATE or DELETE with JOIN missing target alias

When the target table is unaliased but also appears as a join participant with an alias, MySQL flags the duplication.

.

Related Errors

FAQs

Is Error 1066 a syntax or runtime error?

It is a compile-time syntax error raised during query parsing, not during execution.

Can I disable the error with a setting?

No. The error enforces unambiguous table references. You must change the query to fix it.

Does alias case sensitivity matter?

Aliases are case-insensitive on default MySQL installations, so User and user are identical and will still clash.

How does Galaxy help avoid this error?

Galaxys real-time linter flags duplicate aliases before execution, and its AI copilot suggests unique names automatically.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo