Common SQL Errors

MySQL Error 1385: ER_NO_GROUP_FOR_PROC - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The query calls a stored procedure that expects GROUP BY, but the SELECT statement lacks a GROUP clause.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1385?

<p>MySQL Error 1385: ER_NO_GROUP_FOR_PROC appears when a SELECT invokes a stored procedure that uses aggregation but forgets a GROUP BY clause. Add the correct GROUP BY or refactor the routine to remove the dependency on grouping to fix the issue.</p>

Error Highlights

Typical Error Message

Select must have a group with this procedure

Error Type

Runtime Error

Language

MySQL

Symbol

ER_NO_GROUP_FOR_PROC

Error Code

1385

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1385: ER_NO_GROUP_FOR_PROC?

MySQL returns error 1385 when a stored function or procedure that relies on GROUP BY aggregation is invoked from a SELECT statement that lacks the required GROUP clause. The engine stops execution to avoid returning misleading aggregate results.

The error appears in MySQL 5.x and later whenever CALL or SELECT references a routine containing aggregate functions but the outer query omits GROUP BY or aggregate handling. Fixing the query or routine restores execution.

What Causes This Error?

MySQL checks that a SELECT using stored procedures with aggregation also groups the result set. If the calling query does not include GROUP BY, the parser raises ER_NO_GROUP_FOR_PROC to enforce deterministic results.

The error can also surface when a view or trigger calls such a procedure, or when the routine was altered to add aggregates but dependent queries were not updated.

How to Fix MySQL Error 1385

Add an explicit GROUP BY clause that matches the non aggregated columns, or refactor the procedure to remove its dependency on the caller's grouping. Confirm that every SELECT invoking the routine satisfies grouping rules.

If the procedure only returns scalar values, use SELECT ... FROM DUAL or set variables instead of relying on aggregation, eliminating the need for GROUP BY.

Common Scenarios and Solutions

Reporting dashboards often wrap procedures that compute metrics. Ensure the dashboard query groups by the same dimensions used inside the procedure.

ETL scripts that call routines in INSERT INTO ... SELECT statements must include GROUP BY before loading aggregate data into fact tables.

Best Practices to Avoid This Error

Document the contract of each routine, noting whether the caller must supply GROUP BY. Embed ASSERT style checks at the start of procedures to validate input parameters instead of relying on the server error.

Use Galaxy's editor linting to highlight SELECT statements calling aggregation routines without grouping, preventing the problem before runtime.

Related Errors and Solutions

ER_NON_GROUPING_FIELD_USED: raised when non aggregated column appears in SELECT without GROUP BY. Add grouping or aggregation.

ER_WRONG_GROUP_FIELD: occurs when GROUP BY references unfamiliar columns. Ensure listed columns exist in SELECT and tables.

Common Causes

Procedure uses aggregate functions

The routine contains COUNT, SUM, AVG, etc., requiring grouping context from the caller.

Caller omits GROUP BY

The SELECT invoking the procedure fails to include a GROUP BY clause.

View or trigger context

Underlying SELECT in a view or trigger lacks the needed GROUP BY.

Routine updated but queries not

A routine was modified to add aggregation, but dependent queries were not adjusted.

Related Errors

ER_NON_GROUPING_FIELD_USED

Non aggregated column in SELECT without GROUP BY.

ER_WRONG_GROUP_FIELD

GROUP BY contains unknown column or alias.

ER_MIX_OF_GROUP_FUNC_AND_FIELDS

Aggregated and non aggregated columns mixed without GROUP BY.

ER_INVALID_GROUP_FUNC_USE

Aggregate function used improperly in statement.

FAQs

Does MySQL 8 still raise error 1385?

Yes, the grouping rule remains; procedures that need aggregation still trigger error 1385 when the caller lacks GROUP BY.

Can I disable the check?

No server variable removes this validation. Rewrite the query or procedure instead.

Why does MySQL need GROUP BY if I only expect one row?

MySQL cannot guarantee a single row unless grouping or aggregation rules are explicit. The error forces clarity.

How does Galaxy help?

Galaxy's linting flags calls to aggregation procedures without GROUP BY and its AI copilot suggests the corrected query instantly.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo