# ORDER BY position 3 is not in select list / 1st ORDER BY term out of range

Source: https://sqlstreak.com/sql/errors/order-by-position-not-in-select-list · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** A number in ORDER BY means a column position in the select list: `ORDER BY 3` needs at least three selected columns. Sort by the column's name instead, which keeps working when the select list changes.

## The exact messages

- PostgreSQL: `ERROR: ORDER BY position 3 is not in select list`
- SQLite: `1st ORDER BY term out of range - should be between 1 and 2`

## How PostgreSQL prints it

```
ERROR:  ORDER BY position 3 is not in select list
LINE 3: ORDER BY 3;
                 ^
```

## Why it happens

### A column was removed from SELECT

`ORDER BY 3` was right until the third column was deleted. Names don't have this problem.

### A column name in single quotes

`ORDER BY 'price'` is a constant, not a column. PostgreSQL rejects it; SQLite sorts by the same constant for every row, which means no sorting at all.

## The broken query

```sql
SELECT name, price
FROM menu_items
ORDER BY 3;
```

## The fix

```sql
SELECT name, price
FROM menu_items
ORDER BY price DESC, name;
```

Sort by names, not positions. `name` breaks ties between items with the same price.

| name | price |
| --- | --- |
| BBQ Meteor | 15.5 |
| Four Cheese Orbit | 14 |
| Pepperoni Rocket | 13.5 |
| Veggie Nebula | 13 |
| Margherita | 11 |
| Wings | 8.5 |

(6 of 11 rows)
