MySQL – Fix for Query Failed: Expression Not in GROUP BY Clause

greatest-n-per-groupMySQLPHP

MySQL Query Failed: Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 

This bug is fixed using below query. by logging into MySQL console as root user

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

But the problem is that this bug reappears every time i restarts the system.
How to fix this?

Best Answer

That's not a bug. That's 'move to standard'.

Do not fix this problem by change server's SQL Mode. Fix it by altering the queries which uses partial GROUP BY expressions.

Details can be read in MySQL Handling of GROUP BY.