Troubleshooting "SELECT list is not in GROUP BY clause" Error with MySQL
The error "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column" typically occurs in MySQL when the result of a query contains non-aggregated columns that are not included in the GROUP BY clause. This is due to the sql_mode=only_full_group_by setting, which enforces stricter grouping rules.
To address this issue, there are several solutions:
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT * FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type`, `id`
SELECT `proof_type`, COUNT(*) AS `document_count` FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type`
It is important to note that changing the SQL mode is not the best practice. The preferred solution is to modify the query to comply with the stricter grouping rules.
The above is the detailed content of How to Resolve MySQL's 'SELECT list is not in GROUP BY clause' Error?. For more information, please follow other related articles on the PHP Chinese website!