1248ERRORTier 2 — Caution✅ HIGH confidenceEvery derived table must have its own alias
Category: Query SyntaxVersions: All MariaDB / MySQL versions
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
- 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
SELECT avg_salary FROM (
SELECT AVG(salary) AS avg_salary FROM employees
);
-- Missing alias after closing parenthesisERROR 1248 (42000): Every derived table must have its own alias
Fix 1: Add an alias to the derived table
Always — every subquery in FROM must have an alias.
fix
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 docs: https://mariadb.com/kb/en/subqueries-in-a-from-clause/
🔧 Source ref: MariaDB Server error code 1248 / ER_DERIVED_MUST_HAVE_ALIAS
📖 Further reading: MariaDB Subqueries in FROM
Confidence assessment
✅ HIGH confidence
Stable.
See also
🔗 Related errors
📄 Reference pages
derived tableinline viewFROM subquery
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →