Error 42000 Executing Statement: Expression #1 Of SELECT List Is Not In GROUP BY
WHEN & WHERE
The error occurs on the MIGx Manage loading page, specifically when selecting a tab or opening the filters dropdown. This issue is encountered on page MIGx Manage loading, on MIGx tab select, on filters dropdown open.
WHY?
The root cause of this problem lies in the MySQL 5.7.5 and higher versions, which have ONLY_FULL_GROUP_BY mode enabled by default. This mode requires that all non-aggregated columns in a SELECT statement be included in the GROUP BY clause. The MIGx framework executes a query that does not meet this requirement, resulting in error 1055 in xpdoobject.class.php
. However, the actual problem lies in the query generated by MIGx, which can be found in the files migx.class.php
or models in core/components/migx/model/
.
DEBUG
To debug this issue, you can add the following code to the manager admin page's Developer tools console:
console.log('MIGX debug mode activated');
Ext.Ajax.on('requestcomplete', function(conn, response, options) {
if (options.url.indexOf('connector.php') !== -1) {
console.log('MIGX request:', options);
if (response.responseText) {
try {
var data = Ext.decode(response.responseText);
if (data && data.message && data.message.indexOf('ONLY_FULL_GROUP_BY') !== -1) {
console.error('GROUP BY error detected:', data.message);
}
} catch(e) {}
}
}
}, this);
This code will log the MIGx requests and detect if the GROUP BY error is present in the response.
RESULT
After adding the debug code, you will see the following output:
{
action: 'mgr/migxdb/process',
processaction: 'getcombo',
configs: 'migxconfigs',
searchname: 'configcategory'
}
/assets/components/migx/connector.php
NEW ERRORs IN LOG
BUT WHY?!!
To further investigate the issue, you need to modify the connector.php
file in the MIGx component. Add the following code right after the <?php
tag:
<?php
$migxLog = function($message) {
file_put_contents(MIGX_LOG_FILE, date('H:i:s').' - '.$message."\n", FILE_APPEND);
};
try {
$migxLog('Request started: '.print_r($_REQUEST, true));
// Catch all SQL error
$modx->setLogTarget([
'target' => 'FILE',
'options' => [
'filename' => 'migx_sql_errors.log'
]
]);
// General processing
if (isset($_REQUEST['processaction'])) {
$migxLog('Processing action: '.$_REQUEST['processaction']);
}
} catch (Exception $e) {
$migxLog('EXCEPTION: '.$e->getMessage());
header('HTTP/1.1 500 Internal Server Error');
die(json_encode(['success' => false, 'message' => $e->getMessage()]));
}
This code will log all requests and exceptions in migx_sql_errors.log
file.
SOLUTION
After adding the debug code and modifying the connector.php
file, you should see the following output in the migx_sql_errors.log
file:
07:17:16 - Request started: Array
(
[start] => 0
[limit] => 10
[action] => mgr/migxdb/getList
[configs] => migxconfigs
[reqTempParams] =>
[reqConfigs] => packagemanager||migxconfigs||setup
[resource_id] =>
[object_id] =>
[HTTP_MODAUTH] => modx5ed8bd90eb7f62
)
07:17:23 - Request started: Array
(
[combo_id] => all
[action] => mgr/migxdb/process
[processaction] => getcombo
[configs] => migxconfigs
[searchname] => configcategory
[resource_id] =>
[HTTP_MODAUTH] => modx5ed8bd90eb7f62
)
This output will help you identify the requests that are causing the GROUP BY error.
RESOLVING THE ISSUE
To resolve the issue, you need to modify the MIGx queries to include all non-aggregated columns in the GROUP BY clause. You can do this by modifying the migx.class.php
or models in core/components/migx/model/
to include the necessary columns in the GROUP BY clause.
CONCLUSION
Q&A
Q: What is the ONLY_FULL_GROUP_BY mode in MySQL? A: The ONLY_FULL_GROUP_BY mode is a feature in MySQL that requires all non-aggregated columns in a SELECT statement to be included in the GROUP BY clause. This mode is enabled by default in MySQL 5.7.5 and higher versions.
Q: What is the cause of the error 42000 executing statement: Expression #1 of SELECT list is not in GROUP BY? A: The error is caused by the MIGx framework executing a query that does not meet the requirements of the ONLY_FULL_GROUP_BY mode. The MIGx framework generates queries that do not include all non-aggregated columns in the GROUP BY clause, resulting in the error.
Q: How can I debug the issue? A: To debug the issue, you can add the following code to the manager admin page's Developer tools console:
console.log('MIGX debug mode activated');
Ext.Ajax.on('requestcomplete', function(conn, response, options) {
if (options.url.indexOf('connector.php') !== -1) {
console.log('MIGX request:', options);
if (response.responseText) {
try {
var data = Ext.decode(response.responseText);
if (data && data.message && data.message.indexOf('ONLY_FULL_GROUP_BY') !== -1) {
console.error('GROUP BY error detected:', data.message);
}
} catch(e) {}
}
}
}, this);
This code will log the MIGx requests and detect if the GROUP BY error is present in the response.
Q: What is the output of the debug code? A: The output of the debug code will be the MIGx requests and the GROUP BY error message if present.
Q: How can I modify the MIGx queries to resolve the issue?
A: To modify the MIGx queries, you need to include all non-aggregated columns in the GROUP BY clause. You can do this by modifying the migx.class.php
or models in core/components/migx/model/
to include the necessary columns in the GROUP BY clause.
Q: What is the solution to the issue?
A: The solution to the issue is to modify the MIGx queries to include all non-aggregated columns in the GROUP BY clause. This can be done by modifying the migx.class.php
or models in core/components/migx/model/
to include the necessary columns in the GROUP BY clause.
Q: How can I log all requests and exceptions in the MIGx framework?
A: To log all requests and exceptions in the MIGx framework, you can add the following code to the connector.php
file:
<?php
$migxLog = function($message) {
file_put_contents(MIGX_LOG_FILE, date('H:i:s').' - '.$message."\n", FILE_APPEND);
};
try {
$migxLog('Request started: '.print_r($_REQUEST, true));
// Catch all SQL error
$modx->setLogTarget([
'target' => 'FILE',
'options' => [
'filename' => 'migx_sql_errors.log'
]
]);
// General processing
if (isset($_REQUEST['processaction'])) {
$migxLog('Processing action: '.$_REQUEST['processaction']);
}
} catch (Exception $e) {
$migxLog('EXCEPTION: '.$e->getMessage());
header('HTTP/1.1 500 Internal Server Error');
die(json_encode(['success' => false, 'message' => $e->getMessage()]));
}
This code will log all requests and exceptions in the migx_sql_errors.log
file.
Q: What is the output of the logging code? A: The output of the logging code will be all requests and exceptions in the MIGx framework, including the GROUP BY error message if present.
Q: How can I resolve the issue by modifying the MIGx queries?
A: To resolve the issue by modifying the MIGx queries, you need to include all non-aggregated columns in the GROUP BY clause. You can do this by modifying the migx.class.php
or models in core/components/migx/model/
to include the necessary columns in the GROUP BY clause.
Q: What are the benefits of modifying the MIGx queries? A: The benefits of modifying the MIGx queries include resolving the GROUP BY error, improving the performance of the MIGx framework, and ensuring that the MIGx framework is compatible with the ONLY_FULL_GROUP_BY mode in MySQL 5.7.5 and higher versions.