// MySQL error reference

MySQL error 1248: Every derived table must have its own alias

A subquery in the FROM clause has no alias. MySQL requires a name for every derived table, even if you never refer to it.

Error number
1248
Name
ER_DERIVED_MUST_HAVE_ALIAS
SQLSTATE
42000
Category
Syntax and statements
Error message
Every derived table must have its own alias

What it means

A subquery used as a table in FROM or JOIN is a derived table, and MySQL requires it to have an alias. Without one, the statement fails with 1248.

Common causes

  • SELECT COUNT(*) FROM (SELECT ...) with nothing after the closing parenthesis.
  • Queries copied from databases that allow unnamed subqueries.

How to fix it

  1. Add an alias after the closing parenthesis.

    SELECT COUNT(*) FROM (SELECT DISTINCT customer_id FROM orders) AS buyers;

Reproduce it safely

SELECT * FROM (SELECT 1);  -- ERROR 1248 (42000)

Related errors

More syntax and statements errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.