MySQL Error: Expression #3 Not in GROUP BY Clause - 'only_full_group_by' Mode
This error message indicates that your query is trying to group by certain columns, but one of the columns in the SELECT statement is not included in the GROUP BY clause and is not an aggregated column.
To resolve this error, you can either:
- Add the non-grouped column to the GROUP BY clause: This ensures that the query only retrieves data where all the columns in the SELECT statement are identical.
- Use an aggregate function on the non-grouped column in the SELECT statement: Aggregate functions like
SUM(),AVG(),MAX(),MIN(), etc., summarize data within groups. - Disable the 'only_full_group_by' SQL mode: This allows you to select non-grouped columns without adding them to the GROUP BY clause. You can achieve this by modifying the MySQL configuration or by running the following query before executing your actual query:
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
By implementing one of these solutions, you can resolve the 'Expression #3 of SELECT list is not in GROUP BY clause' error and ensure your query functions correctly.
原文地址: https://www.cveoy.top/t/topic/op3N 著作权归作者所有。请勿转载和采集!