mysqldude
Error codes › 1172

MySQL & MariaDB error 1172: Result consisted of more than one row

Error messageResult 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.

MySQLMariaDB
SymbolER_TOO_MANY_ROWSER_TOO_MANY_ROWS
SQLSTATE4200042000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery 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 WHERE clause 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 FOUND catches.

How to fix it

  • Decide which row you want and say so: ORDER BY created DESC LIMIT 1, or an aggregate such as MIN(id).
  • If the value is meant to be unique, add a UNIQUE key 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.

  1. Connect with mysql -u root -p and 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');
  2. 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

  1. 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

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.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

Related errors

  • 1242 ER_SUBQUERY_NO_1_ROWexplained
  • 1329 ER_SP_FETCH_NO_DATA