3191
MariaDBERRORNotableQuery SyntaxHIGH confidence

Field in GROUPING() is not in GROUP BY

Production Risk

Low — caught at parse time.

Why it happens
  1. 1Passing a column to the GROUPING() function that is not listed in the GROUP BY clause.
  2. 2GROUPING() only accepts columns used in the GROUP BY WITH ROLLUP context.
How to reproduce
trigger — this will error
trigger — this will error
SELECT col1, GROUPING(col2) FROM t1 GROUP BY col1 WITH ROLLUP;

expected output

ERROR 3191 (HY000): Argument of GROUPING() must be in GROUP BY.

Fix

Add the column to GROUP BY

Add the column to GROUP BY
SELECT col1, col2, GROUPING(col2) FROM t1 GROUP BY col1, col2 WITH ROLLUP;

Why this works

GROUPING() operates on ROLLUP super-aggregate rows, requiring the column in GROUP BY.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3191 ER_FIELD_IN_GROUPING_NOT_GROUP_BY

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors