# more than one row returned by a subquery used as an expression

Source: https://sqlstreak.com/sql/errors/more-than-one-row-returned-by-subquery · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** A subquery used with `=` must return exactly one value, but yours returns several rows. Use `IN (subquery)` to match any of them, or `EXISTS` for a correlated check.

## The exact messages

- PostgreSQL: `ERROR: more than one row returned by a subquery used as an expression`

## How PostgreSQL prints it

```
ERROR:  more than one row returned by a subquery used as an expression
```

## Why it happens

### Using = where you meant IN

“Customers who placed a delivered order” matches many customers, so the subquery returns many ids.

### A lookup that isn't unique

If you expect one row, the data has duplicates. Add a stricter condition, or `LIMIT 1` with an `ORDER BY` if any one row is fine.

## The broken query

```sql
SELECT name FROM customers
WHERE id = (SELECT customer_id FROM orders
            WHERE status = 'delivered');
```

## The fix

```sql
SELECT name FROM customers
WHERE id IN (SELECT customer_id FROM orders
             WHERE status = 'delivered');
```

`IN` accepts a list of values, so every matching customer is returned.

| name |
| --- |
| Maya Ortiz |
| Jonah Reed |
| Tomás Herrera |
| Ellie Park |
| Sam Okafor |
| Lena Fischer |

(6 of 7 rows)

## What SQLite does instead

SQLite silently uses the first row the subquery returns. The query “works”, but returns only part of the answer: here one customer instead of all of them.
