SQLWarningRuntime ErrorJune 12, 2026

Runtime Error

SQL Error (1242): Subquery returns more than one row

What This Error Means

This error occurs when a subquery is expected to return a single value, but it actually returns multiple rows. This can happen when a subquery is used with an aggregate function, but the GROUP BY clause is missing or incorrect.

Why It Happens

This error usually happens when a subquery is not properly correlated with the outer query. For example, if a subquery is used to retrieve a list of IDs, but the outer query is trying to retrieve a single value based on that ID. It can also happen when a subquery is used with an aggregate function, but the GROUP BY clause is missing or incorrect.

How to Fix It

  1. 1To fix this error, you need to ensure that the subquery returns a single value. This can be done by adding a GROUP BY clause to the subquery, or by using a different query structure that does not rely on a subquery. Here's an example:

Example Code Solution

❌ Before (problematic code)
SQL
SELECT * FROM customers
WHERE country = (SELECT country FROM customers WHERE id = 1);
✅ After (fixed code)
SQL
SELECT c.* FROM customers c
JOIN (SELECT country FROM customers WHERE id = 1) AS subquery ON c.country = subquery.country;

Fix for SQL Error (1242): Subquery returns more than one row

Related SQL Errors

Related SQL Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error