Too many tables — MySQL can only use 61 tables in a join
Production Risk
Medium — query fails; application must redesign the query.
ER_TOO_MANY_TABLES (1116, SQLSTATE HY000) is raised when a single query joins more than 61 tables. This is a hard limit in the MySQL query optimizer.
- 1A single SELECT joins more than 61 tables directly
- 2A complex ORM-generated query fans out to too many joined tables
- 3A view references many tables and is then joined with more tables
-- SELECT that joins 62+ tables
expected output
ERROR 1116 (HY000): Too many tables; MySQL can only use 61 tables in a join
Fix
Refactor the query to use subqueries or temporary tables
WHEN A join genuinely requires more than 61 tables.
-- Split into stages using temporary tables: CREATE TEMPORARY TABLE stage1 AS SELECT ... FROM t1 JOIN t2 ... JOIN t30 ...; SELECT ... FROM stage1 JOIN t31 ... ;
Why this works
Breaking the join into stages keeps each individual query under the 61-table limit while allowing the full computation.
✕ Denormalize the entire schema to avoid joins
Denormalization for query performance should be a measured decision; a 62-table join usually indicates a schema design issue worth solving properly.
MySQL 8.0 — 1116 ER_TOO_MANY_TABLES
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev