3186
MySQLERRORNotableWindow FunctionsHIGH confidence

Window function requires GROUP BY or ORDER BY

Production Risk

Low — caught at validation time.

Why it happens
  1. 1Using GROUPS framing without an ORDER BY clause in the window definition.
How to reproduce
trigger — this will error
trigger — this will error
SELECT RANK() OVER (GROUPS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM t1;

expected output

ERROR 3186 (HY000): Window function with GROUPS requires an ORDER BY clause.

Fix

Add ORDER BY to the window clause

Add ORDER BY to the window clause
SELECT RANK() OVER (ORDER BY id GROUPS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM t1;

Why this works

GROUPS frame requires ordering to define peer groups.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3186 ER_WINDOW_NO_GROUP_ORDER

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

← All MySQL errors