GROUP BY SQL Origin: Data OSI layer 7 · Application Last updated 14 Oct 2026

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

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

Exact message you may see must appear in the GROUP BY clauseisn't in GROUP BYnot functionally dependentnonaggregated column
Seen on: MySQL PostgreSQL SQL

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

102 — SQL Server: Incorrect syntax near 'x'. (Msg 102) (SQL)1021064 — MySQL ERROR 1064 (42000): You have an error in your SQL syntax (MySQL)10641066 — MySQL ERROR 1066 (42000): Not unique table/alias: 'x' (SQL)10661136 — MySQL ERROR 1136 (21S01): Column count doesn't match value count at row 1 (SQL)11361222 — MySQL ERROR 1222 (21000): The used SELECT statements have a different number of columns (SQL)12221248 — MySQL ERROR 1248 (42000): Every derived table must have its own alias (SQL)124842601 — ERROR: syntax error at or near "x" (PostgreSQL)426018120 — SQL Server Msg 8120: Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause (SQL)8120GROUP BY

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.