Not unique table/alias in query
Production Risk
Low — query is rejected; no data is affected.
ER_NONUNIQ_TABLE (1066, SQLSTATE 42000) is raised when a query references the same table (or uses the same alias) more than once in the FROM clause without distinguishing aliases.
- 1The same table appears twice in a JOIN without distinct aliases
- 2A subquery or CTE uses the same alias as an outer table
SELECT * FROM orders, orders;
expected output
ERROR 1066 (42000): Not unique table/alias: 'orders'
Fix
Assign unique aliases to each table reference
WHEN Self-join or repeated table reference is intentional.
SELECT a.id, b.id FROM orders AS a JOIN orders AS b ON a.customer_id = b.customer_id AND a.id <> b.id;
Why this works
Unique aliases disambiguate each table reference so MySQL can resolve column names correctly.
✕ Remove one of the table references to fix 1066 without understanding the query
Self-joins are intentional in some queries; removing a reference changes query semantics.
MySQL 8.0 — 1066 ER_NONUNIQ_TABLE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev