Help Center/ Database and Application Migration UGO/ User Guide/ Syntax Conversion/ Conversion Error Codes/ Error Codes Generated During Conversion from MySQL to GaussDB/ U0400037: GaussDB does not support non-aggregation columns that are not in the GROUP BY clause in SELECT by default
Updated on 2025-06-07 GMT+08:00

U0400037: GaussDB does not support non-aggregation columns that are not in the GROUP BY clause in SELECT by default

Description

Database Type and Version

  • Source database type and version: MySQL 5.5, 5.6, 5.7, and 8.0
  • Target database type and version: all GaussDB versions

Syntax Example

The GROUP BY clause groups query results based on the values of one or more columns. The query results with the same value are in the same group. If the SELECT list expression references fields that are not grouped, this error is reported unless aggregate functions are used, because multiple values may be returned from ungrouped fields. The query result is uncertain. For example:

SELECT id, code FROM test_code group by code;

When the GROUP BY clause is omitted and the aggregate function is used, the entire query result set is considered as a large group. In this case, if both the aggregate function and common columns exist in the SELECT list, this error is reported. For example:

SELECT max(id), code FROM test_code;

If the value of sql_mode in MySQL does not contain ONLY_FULL_GROUP_BY, the preceding two queries are supported. The query results of non-aggregation columns that are not in the GROUP BY clause are uncertain. In MySQL 5.7 and later versions, ONLY_FULL_GROUP_BY is added for sql_mode by default.

Suggestion

You can use either of the following methods:

  1. If the GUC parameter of GaussDB supports sql_mode, remove ONLY_FULL_GROUP_BY.
  2. Modify the query statement and related application code to meet group query specifications of the SQL standard.