1066
MariaDBERRORCommonQueryHIGH confidence

Not unique table/alias in query

Production Risk

Low — query is rejected; no data is affected.

What this means

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.

Why it happens
  1. 1The same table appears twice in a JOIN without distinct aliases
  2. 2A subquery or CTE uses the same alias as an outer table
How to reproduce
trigger — this will error
trigger — this will error
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.

Assign unique aliases to each table reference
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.

What not to do

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.

Sources
Official documentation ↗

MySQL 8.0 — 1066 ER_NONUNIQ_TABLE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors