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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3