mysqldude
Error codes › 1055

MySQL & MariaDB error 1055: Expression is not in GROUP BY clause (only_full_group_by)

Error message'…' isn't in GROUP BY
Example from our test runs: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 't_0.sales.rep' which is not functionally dependent on columns in GROUP (5.7.44)

With ONLY_FULL_GROUP_BY, every selected column must be grouped, aggregated, or functionally dependent on the grouped columns. The query selects one that isn't, so the server won't pick an arbitrary value for you.

MySQLMariaDB
SymbolER_WRONG_FIELD_WITH_GROUPER_WRONG_FIELD_WITH_GROUP
SQLSTATE4200042000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'shop.sales.rep' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.

In SELECT region, rep, SUM(amount) … GROUP BY region there are several rep values per region, and the query doesn’t say which one you want. Older MySQL simply returned one of them, unpredictably.

Why it happens

  • ONLY_FULL_GROUP_BY has been in MySQL’s default sql_mode since 5.7.5, so queries written for 5.6 start failing after an upgrade. MySQL 5.6 and MariaDB don’t enable it by default (our tests show the default behaviour per version).
  • Selecting extra descriptive columns “for convenience” alongside an aggregate.

How to fix it

  • Group by every selected column that isn’t aggregated: GROUP BY region, rep.
  • Aggregate it: MAX(rep), MIN(rep), GROUP_CONCAT(rep).
  • Say you don’t care which value: ANY_VALUE(rep) (MySQL 5.7+).
  • Group by the primary key: columns that depend on it are then allowed (functional dependency).
  • Removing ONLY_FULL_GROUP_BY from sql_mode makes the error go away but brings back unpredictable results.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE sales (region VARCHAR(10), rep VARCHAR(10), amount INT);
    INSERT INTO sales VALUES ('east','ann',10),('east','bob',20),('west','cy',5);
  2. Run:

    SET SESSION sql_mode = CONCAT(@@sql_mode, ',ONLY_FULL_GROUP_BY');
    SELECT region, rep, SUM(amount) FROM sales GROUP BY region;

You get: 't_0.sales.rep' isn't in GROUP BY(11.8.9)

Verified fixes

  1. Say which value you want: ANY_VALUE(), MIN()/MAX(), or add it to GROUP BY

    SELECT region, MAX(rep), SUM(amount) FROM sales GROUP BY region ORDER BY region;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
With ONLY_FULL_GROUP_BY on, select a column that is neither grouped nor aggregated
repro
✓ 1055✓ 1055✓ 1055✓ 1055✓ 1055✓ 1055✓ 1055✓ 1055✓ 1055
Same query with the server's default sql_mode (ONLY_FULL_GROUP_BY is default on MySQL 5.7+ only)
version check
≠✓ 1055✓ 1055✓ 1055✓ 1055≠≠≠≠
Say which value you want: ANY_VALUE(), MIN()/MAX(), or add it to GROUP BY
fix
✓✓✓✓✓✓✓✓✓
With ONLY_FULL_GROUP_BY on, select a column that is neither grouped nor aggregated repro
MySQL 5.6✓ 10555.7✓ 10558.0✓ 10558.4✓ 10559✓ 1055
MariaDB 10.6✓ 105510.11✓ 105511.4✓ 105511.8✓ 1055
Same query with the server's default sql_mode (ONLY_FULL_GROUP_BY is default on MySQL 5.7+ only) version check
MySQL 5.6≠5.7✓ 10558.0✓ 10558.4✓ 10559✓ 1055
MariaDB 10.6≠10.11≠11.4≠11.8≠
Say which value you want: ANY_VALUE(), MIN()/MAX(), or add it to GROUP BY fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (1)
  • Same query with the server's default sql_mode (ONLY_FULL_GROUP_BY is default on MySQL 5.7+ only) (MySQL 5.6, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1055 did not occur

Related errors

  • 1140 ER_MIX_OF_GROUP_FUNC_AND_FIELDS
  • 3065 ER_FIELD_IN_ORDER_NOT_SELECT