1116
MariaDBERRORNotableQueryHIGH confidence

Too many tables — MySQL can only use 61 tables in a join

Production Risk

Medium — query fails; application must redesign the query.

What this means

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.

Why it happens
  1. 1A single SELECT joins more than 61 tables directly
  2. 2A complex ORM-generated query fans out to too many joined tables
  3. 3A view references many tables and is then joined with more tables
How to reproduce
trigger — this will error
trigger — this will error
-- 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.

Refactor the query to use subqueries or temporary 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.

What not to do

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.

Sources
Official documentation ↗

MySQL 8.0 — 1116 ER_TOO_MANY_TABLES

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors