1248
MariaDBERRORNotableQuery SyntaxHIGH confidence

Every derived table must have its own alias

What this means

Error 1248 (SQLSTATE 42000) is raised when a derived table (a subquery used in the FROM clause) does not have an alias. The SQL standard and MySQL/MariaDB both require that every inline view in the FROM clause be aliased.

Why it happens
  1. 1A subquery in the FROM clause is missing an AS alias
How to reproduce

Using a subquery in FROM without an alias.

trigger — this will error
trigger — this will error
SELECT avg_salary FROM (
  SELECT AVG(salary) AS avg_salary FROM employees
);
-- Missing alias after closing parenthesis

expected output

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

Fix

Add an alias to the derived table

WHEN Always — every subquery in FROM must have an alias.

Add an alias to the derived table
SELECT avg_salary FROM (
  SELECT AVG(salary) AS avg_salary FROM employees
) AS salary_summary;

Why this works

The alias (here salary_summary) allows the outer query to reference the derived table. The AS keyword is optional but recommended for clarity.

Sources
Official documentation ↗

MariaDB Server error code 1248 / ER_DERIVED_MUST_HAVE_ALIAS

MariaDB Subqueries in FROM

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

← All MariaDB errors