mysqldude
Error codes › 1242

MySQL & MariaDB error 1242: Subquery returns more than 1 row

Error messageSubquery returns more than 1 row
Example from our test runs: Subquery returns more than 1 row (5.6.51)

A subquery used as a single value (in a SELECT list, or with =, <, >) returned several rows, so the server can't tell which one you mean.

MySQLMariaDB
SymbolER_SUBQUERY_NO_1_ROWER_SUBQUERY_NO_1_ROW
SQLSTATE2100021000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

A scalar subquery must return at most one row and one column. SELECT id, (SELECT boss FROM dept WHERE dept.name = emp.dept) … works until one department has two bosses; then the statement fails for the whole query, not just that row.

Why it happens

  • The data changed: a lookup that “always” matched one row now matches two (duplicate rows, missing unique key).
  • WHERE col = (SELECT …) where IN (SELECT …) was meant.
  • A correlated subquery missing part of its join condition.

How to fix it

  • If several rows are valid, use IN, EXISTS or a JOIN instead of =.
  • If you want one specific row, say which: ORDER BY … LIMIT 1, or an aggregate (MIN(), MAX(), GROUP_CONCAT()).
  • If only one row should ever match, add a UNIQUE key to enforce it, and find the duplicates with GROUP BY … HAVING COUNT(*) > 1.

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));
    CREATE TABLE dept (name VARCHAR(10), boss VARCHAR(10));
    INSERT INTO emp VALUES (1,'it');
    INSERT INTO dept VALUES ('it','ann'),('it','bob');
  2. Run:

    SELECT id, (SELECT boss FROM dept WHERE dept.name = emp.dept) AS boss FROM emp;

You get: Subquery returns more than 1 row(11.8.9)

Verified fixes

  1. Decide which row you want (LIMIT 1 with ORDER BY, an aggregate) or use IN / JOIN

    SELECT id, (SELECT MIN(boss) FROM dept WHERE dept.name = emp.dept) AS boss FROM emp;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
A scalar subquery (used as a value) finds two rows
repro
✓ 1242✓ 1242✓ 1242✓ 1242✓ 1242✓ 1242✓ 1242✓ 1242✓ 1242
Decide which row you want (LIMIT 1 with ORDER BY, an aggregate) or use IN / JOIN
fix
✓✓✓✓✓✓✓✓✓
A scalar subquery (used as a value) finds two rows repro
MySQL 5.6✓ 12425.7✓ 12428.0✓ 12428.4✓ 12429✓ 1242
MariaDB 10.6✓ 124210.11✓ 124211.4✓ 124211.8✓ 1242
Decide which row you want (LIMIT 1 with ORDER BY, an aggregate) or use IN / JOIN 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

  • 1241 ER_OPERAND_COLUMNS
  • 1172 ER_TOO_MANY_ROWSexplained