# each UNION query must have the same number of columns

Source: https://sqlstreak.com/sql/errors/union-same-number-of-columns · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** Every SELECT in a `UNION` must return the same number of columns, in the same order and compatible types. Add the missing column, or a placeholder like `NULL AS city`.

## The exact messages

- PostgreSQL: `ERROR: each UNION query must have the same number of columns`
- SQLite: `do not have the same number of result columns`

## How PostgreSQL prints it

```
ERROR:  each UNION query must have the same number of columns
LINE 3: SELECT name FROM staff;
               ^
```

## Why it happens

### One side has an extra or missing column

Count the columns on each side. Columns are matched by position, not by name.

### SELECT * on tables with different shapes

Two tables rarely have identical columns. List the columns explicitly.

## The broken query

```sql
SELECT name, city FROM customers
UNION
SELECT name FROM staff;
```

## The fix

```sql
SELECT name, city FROM customers
UNION
SELECT name, city FROM staff;
```

Both sides now return name and city. If a table lacks a column, select `NULL AS city` in its place.

| name | city |
| --- | --- |
| Omar Haddad | Austin |
| Diego Santos | Denver |
| Yuki Tanaka | Austin |
| Ivan Petrov | Denver |
| Lia Moreau | Denver |
| Ellie Park | Denver |

(6 of 18 rows)
