MySQL ERROR 1248 (42000): Every derived table must have its own alias
A subquery in FROM wasn’t given an alias.
Seen on:
SQL
Meaning
MySQL (and PostgreSQL before 16) require an alias for every derived table: FROM (SELECT …) AS t.
Common causes
- Subquery in FROM without AS alias
- Query ported from PostgreSQL 16+/SQL Server that allows omitting it
⚡ Quick fix
- Add an alias after the closing parenthesis
- Alias every derived table even when not referenced
Detailed fix by platform
SQL
SELECT t.user_id, t.cnt FROM (SELECT user_id, COUNT(*) cnt FROM orders GROUP BY user_id) AS t;
How to diagnose
- Subquery — Alias present?
- Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026