Common SQL Errors

MySQL Error 1172: ER_TOO_MANY_ROWS – Result consisted of more than one row

Galaxy Team
August 6, 2025

MySQL raises ER_TOO_MANY_ROWS when a query that must return a single row or value instead produces multiple rows.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1172 (ER_TOO_MANY_ROWS)?

MySQL Error 1172: ER_TOO_MANY_ROWS appears when a subquery, SELECT INTO, or single-row UPDATE/DELETE returns more than one row. Limit the result set or add filtering conditions to ensure only one row is produced, then rerun the statement.

Error Highlights

Typical Error Message

ER_TOO_MANY_ROWS

Error Type

Runtime Error

Language

MySQL

Symbol

Result consisted of more than one row

Error Code

1172

SQL State

42000

Explanation

Table of Contents

What is MySQL error 1172 (ER_TOO_MANY_ROWS)?

MySQL throws ER_TOO_MANY_ROWS when an SQL statement expects a single-row result but the executed query produces two or more rows. The server cannot decide which value to pick, so it stops and returns error 1172 instead of guessing.

Error 1172 commonly surfaces in SELECT ... INTO, INSERT ... SELECT, scalar subqueries, or UPDATE/DELETE commands that use a subquery in the WHERE or SET clause.

All those patterns require exactly one row to proceed.

When does this error occur in real projects?

Developers hit ER_TOO_MANY_ROWS while joining tables without restrictive predicates, omitting PRIMARY KEY filters in correlated subqueries, or forgetting LIMIT 1 in aggregation-free queries. Any time the database must collapse multiple rows into one scalar, the risk exists.

Why is it urgent to fix?

Leaving this error unresolved blocks data changes, breaks application logic, and may hide deeper data quality issues such as missing unique constraints.

Quick remediation restores application uptime and preserves data consistency.

What Causes This Error?

The primary trigger is a non-unique result set inside a context that demands uniqueness. Missing WHERE clauses, duplicate data, and inadequate JOIN conditions top the list. Even well-written queries fail if data unexpectedly duplicates.

How to Fix MySQL Error 1172: ER_TOO_MANY_ROWS

Identify which subquery or SELECT statement returns too many rows by running it in isolation. Add filtering predicates, GROUP BY with aggregation, ORDER BY ...

LIMIT 1, or DISTINCT to reduce the output to one row. Alternatively, redesign the schema with UNIQUE constraints.

Common Scenarios and Solutions

For UPDATE with a subquery, add LIMIT 1 to the subquery or change to JOIN syntax with keys. For SELECT ... INTO, aggregate with MAX() or MIN() to obtain a single value. In INSERT ... SELECT, ensure the FROM clause yields exactly one row before insertion.

Best Practices to Avoid This Error

Define PRIMARY KEY and UNIQUE constraints to guarantee single-row lookups.

Always test subqueries alone during development. Use LIMIT 1 when only the first matching row matters. Monitor slow queries for exploding result sets in production.

Related Errors and Solutions

Error 1242 (Subquery returns more than 1 row) is similar but raised within the subquery context. Error 1064 (syntax) differs because it arises from malformed SQL. Error 1451 (foreign key constraint) concerns relational integrity, not result set size.

.

Common Causes

Related Errors

FAQs

Is LIMIT 1 always safe to silence error 1172?

LIMIT 1 removes the error but may hide data issues. Confirm that returning any row is logically sound before applying it.

Does this error indicate corrupted data?

Not necessarily. It signals duplicate rows where uniqueness was assumed. Validate constraints to detect real corruption.

Will adding a UNIQUE index fix future occurrences?

Yes. A UNIQUE or PRIMARY KEY constraint forces single-row matches and prevents the error from resurfacing for that column set.

How does Galaxy help avoid ER_TOO_MANY_ROWS?

Galaxy's AI copilot previews subquery results, flags multi-row outputs in the editor, and suggests LIMIT or aggregation before running the statement.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo