Download

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

A subquery used as a table, in FROM or JOIN, has no name after its closing bracket. Add one: FROM (SELECT …) AS t. MariaDB reports the same mistake as a syntax error (1064).

MySQL error 1248· Tested on MySQL 8.4.11 and MariaDB 11.4.13· Updated 11 October 2026

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

What it means

A derived table is a subquery in the FROM clause or a JOIN, used as if it were a table: FROM (SELECT …). SQL requires every table in FROM to have a name the rest of the query can refer to, and a subquery has none of its own, so you must give it an alias after the closing bracket. Error 1248 means at least one is missing. The query doesn’t run.

The alias is required even when nothing refers to it, as in SELECT COUNT(*) FROM (SELECT …).

Common causes

  1. Counting or filtering the result of a query: SELECT COUNT(*) FROM (SELECT DISTINCT …).
  2. Joining to a subquery and naming only the other tables.
  3. Nested brackets: FROM ((SELECT …)), where the alias is needed after the outer bracket.
  4. SQL written for a database that doesn’t require the alias: PostgreSQL 16 and later accept SELECT * FROM (SELECT 1), which PostgreSQL 15 and MySQL refuse.
  5. The 1093 workaround (wrapping a subquery so an UPDATE or DELETE can read its own table), written without the inner alias.

How to fix it

Name the derived table

Put AS and a name after the closing bracket (AS is optional, the name isn’t):

SELECT COUNT(*) FROM (SELECT email FROM emails GROUP BY email) AS t;

Give each one its own name

Every derived table in the query needs one, and they must differ:

SELECT e.email, latest.max_id
FROM emails e
JOIN (SELECT email, MAX(id) AS max_id FROM emails GROUP BY email) AS latest
  ON latest.email = e.email;

Use the alias to refer to the derived table’s columns (latest.max_id), and give computed columns inside it a name too (MAX(id) AS max_id), so they’re easy to refer to.

Or use a CTE

A common table expression (MySQL 8.0 and MariaDB 10.2 and later) names the subquery up front:

WITH latest AS (SELECT email, MAX(id) AS max_id FROM emails GROUP BY email)
SELECT e.email, latest.max_id FROM emails e JOIN latest ON latest.email = e.email;

Reproduce it

On MySQL 8.4.11:

SELECT * FROM (SELECT 1);
SELECT COUNT(*) FROM (SELECT email FROM emails GROUP BY email);
SELECT * FROM (SELECT 1) JOIN (SELECT 2) t2;
SELECT * FROM ((SELECT email FROM emails));
SELECT * FROM emails e JOIN (SELECT email, MAX(id) m FROM emails GROUP BY email) ON 1=1;
ERROR 1248 (42000): Every derived table must have its own alias
ERROR 1248 (42000): Every derived table must have its own alias
ERROR 1248 (42000): Every derived table must have its own alias
ERROR 1248 (42000): Every derived table must have its own alias
ERROR 1248 (42000): Every derived table must have its own alias

With AS t after the subquery, the count returned 3.

MariaDB 11.4.13 rejected the same statements, but as a syntax error pointing right after the subquery (an empty near '' means the end of the statement):

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JOIN (SELECT 2) t2' at line 1

So on MariaDB, a syntax error right after a FROM (…) subquery is often this missing alias.

In Inlet

Inlet shows a syntax error at the position the server reports, so on MariaDB the editor marks where the parser stopped: the word after the subquery, or the end of the statement. When the query fails, Inlet shows the error and links to its page; with your own Anthropic API key, Ask Claude (Pro, ⌘L) can fix the statement.

Inlet: a database client for the Mac

One native app for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and Redis. It explains errors where they happen, holds your edits until you save them, and keeps production read-only until you say so.

Version 0.1.0 · macOS 26 Tahoe or later · Apple silicon and Intel