3285
MySQLERRORNotableCTEsHIGH confidence
Derived table cannot be used in this context with CTE
Production Risk
Low — query is rejected; rename the derived table.
How to reproduce
trigger — this will error
trigger — this will error
WITH cte AS (SELECT * FROM t1) SELECT * FROM (SELECT * FROM cte) cte;
expected output
ERROR 3285 (HY000): Derived table 'cte' has the same name as a CTE.
Fix
Rename the derived table alias
Rename the derived table alias
WITH cte AS (SELECT * FROM t1) SELECT * FROM (SELECT * FROM cte) derived_alias;
Why this works
Using a unique alias for the derived table avoids the name collision.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3285 ER_DERIVED_TABLE_WITH_CTE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev