1295
MariaDBerrorsyntaxhigh confidence

Every derived table must have its own alias

Production Risk

Low — syntax error; query not executed.

What this means

A subquery used as a derived table in the FROM clause was not given an alias.

Why it happens
  1. 1Writing FROM (SELECT ...) without AS alias
  2. 2Forgetting the alias after a subquery in a JOIN
How to reproduce
trigger — this will error
trigger — this will error
SELECT * FROM (SELECT id FROM users);

expected output

ERROR 1295 (42000): Every derived table must have its own alias

Fix

Add an alias to the derived table

Add an alias to the derived table
SELECT * FROM (SELECT id FROM users) AS u;

Why this works

MySQL requires a name to reference the derived table in the outer query.

Sources
Official documentation ↗

MySQL 8.0 — 1295 ER_DERIVED_MUST_HAVE_ALIAS

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

← All MariaDB errors