# Column must appear in the GROUP BY clause / isn't in GROUP BY (MySQL 1055 only_full_group_by)

**Code:** `GROUP BY` · **Category:** SQL · **Seen on:** MySQL, PostgreSQL, SQL

You selected a column that is neither grouped nor aggregated, so the result would be ambiguous.

## Meaning

Each output row of a GROUP BY represents many input rows. Non-aggregated columns must be in the GROUP BY (or functionally dependent on it). MySQL 5.7+ enforces this with `ONLY_FULL_GROUP_BY` (error 1055); PostgreSQL always has.

## Common causes

- SELECT includes a column not in GROUP BY and not aggregated
- Code written for old MySQL defaults that silently picked a random row
- ORDER BY a non-grouped column

## Quick fix

1. Add the column to GROUP BY, or wrap it in an aggregate (MAX, MIN, ANY_VALUE)
2. Group by the primary key when selecting many columns from that table
3. Avoid disabling ONLY_FULL_GROUP_BY — it hides real bugs

## Detailed fix by platform

### SQL

1. Aggregate or group explicitly:

```sql
-- ❌ which order's created_at should be shown per customer?
SELECT customer_id, created_at, COUNT(*) FROM orders GROUP BY customer_id;
-- ✅
SELECT customer_id, MAX(created_at) AS last_order, COUNT(*) AS orders
FROM orders GROUP BY customer_id;
```


## How to diagnose

1. **Column** — Which column is named?
2. **Intent** — Which value do you actually want per group?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/sql/column-must-appear-in-group-by)
