# subquery has too many columns / sub-select returns 2 columns - expected 1

Source: https://sqlstreak.com/sql/errors/subquery-has-too-many-columns · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** A subquery used with `IN`, `=` or as a value must return exactly one column. Select only the column you compare against: `WHERE id IN (SELECT item_id FROM order_items)`.

## The exact messages

- PostgreSQL: `ERROR: subquery has too many columns`
- SQLite: `sub-select returns 2 columns - expected 1`

## How PostgreSQL prints it

```
ERROR:  subquery has too many columns
LINE 2: WHERE id IN (SELECT item_id, quantity FROM order_items);
                 ^
```

## Why it happens

### An extra column in an IN subquery

`WHERE id IN (SELECT item_id, quantity …)` compares one value with two columns. Keep only `item_id`.

### SELECT * inside the subquery

`IN (SELECT * FROM …)` returns every column. Name the one you need.

### A scalar subquery with two columns

A subquery in SELECT must produce one value. Need two? Use a JOIN, or two subqueries.

## The broken query

```sql
SELECT name FROM menu_items
WHERE id IN (SELECT item_id, quantity FROM order_items);
```

## The fix

```sql
SELECT name FROM menu_items
WHERE id IN (SELECT item_id FROM order_items);
```

One column on each side of IN: the item id.

| name |
| --- |
| Margherita |
| Pepperoni Rocket |
| Four Cheese Orbit |
| BBQ Meteor |
| Veggie Nebula |
| Garlic Knots |

(6 of 11 rows)
