Subquery returns more than 1 row (MySQL 1242) / more than one row returned by a subquery used as an expression
A subquery used where a single value is expected (= (SELECT …)) returned several rows.
Meaning
Scalar subqueries must return at most one row. Data that “should” be unique (one address per user, one active price) often isn’t, and the query breaks the day a duplicate appears.
Common causes
- Duplicate data where you assumed uniqueness
- Missing condition in the subquery
- Using
=whereINwas intended
⚡ Quick fix
- Use
IN (…)/EXISTSif multiple rows are valid - Add
ORDER BY … LIMIT 1when you want one specific row - Add a UNIQUE constraint if duplicates are a data bug
Detailed fix by platform
SQL
- Pick one row deliberately, or use IN:sql
SELECT * FROM users WHERE id IN (SELECT user_id FROM orders WHERE total > 1000); SELECT u.*, (SELECT a.city FROM addresses a WHERE a.user_id = u.id ORDER BY a.is_primary DESC, a.id LIMIT 1) AS city FROM users u;
How to diagnose
- Subquery — Run it alone — how many rows?
- Intent — One value or a set?
- Data — Should a constraint prevent duplicates?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026