Error codes › 1172
MySQL & MariaDB error 1172: Result consisted of more than one row
Example from our test runs:
Result consisted of more than one row (5.6.51) SELECT ... INTO variables matched more than one row. Common in stored procedures. Make the query return exactly one row.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_TOO_MANY_ROWS | ER_TOO_MANY_ROWS |
| SQLSTATE | 42000 | 42000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
SELECT … INTO @var (or into local variables in a stored routine) can only store one row. When the query matches two or more, the statement fails with 1172 and the variables keep their old values.
Why it happens
- The
WHEREclause isn’t selective enough:SELECT id INTO v_id FROM emp WHERE dept = 'it'when the department has several employees. - Data that used to be unique isn’t any more: there was no unique key, and a duplicate slipped in. Procedures that worked for years then start failing.
- A join multiplies rows.
- The opposite case, no row at all, isn’t an error: it raises warning/condition 1329 “No data - zero rows fetched”, which a
CONTINUE HANDLER FOR NOT FOUNDcatches.
How to fix it
- Decide which row you want and say so:
ORDER BY created DESC LIMIT 1, or an aggregate such asMIN(id). - If the value is meant to be unique, add a
UNIQUEkey so duplicates can’t be inserted in the first place. - To process every matching row, use a cursor or a set-based statement instead of
SELECT … INTO.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE emp (id INT, dept VARCHAR(10)); INSERT INTO emp VALUES (1,'it'),(2,'it');Run:
SELECT id INTO @emp_id FROM emp WHERE dept = 'it';
You get: Result consisted of more than one row(11.8.9)
Verified fixes
Make the query return one row: a unique key, an aggregate, or ORDER BY ... LIMIT 1
SELECT id INTO @emp_id FROM emp WHERE dept = 'it' ORDER BY id LIMIT 1; SELECT @emp_id;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| SELECT ... INTO a variable matches two rows repro | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 | ✓ 1172 |
| Make the query return one row: a unique key, an aggregate, or ORDER BY ... LIMIT 1 fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
SELECT ... INTO a variable matches two rows repro
MySQL 5.6✓ 11725.7✓ 11728.0✓ 11728.4✓ 11729✓ 1172
MariaDB 10.6✓ 117210.11✓ 117211.4✓ 117211.8✓ 1172
Make the query return one row: a unique key, an aggregate, or ORDER BY ... LIMIT 1 fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9