I have upgraded my system and have installed MySql 5.7.9 with php for a web application I am working on. I have a query that is dynamically created, and when run in older ve
You can add a unique index
to group_id
; if you are sure that group_id
is unique.
It can solve your case without modifying the query.
A late answer, but it has not been mentioned yet in the answers. Maybe it should complete the already comprehensive answers available. At least it did solve my case when I had to split a table with too many fields.
The consensus answer above is good but if you've got problems running queries within stored procedures after fixing your my.cnf file, then try loading your SPs again.
I suspect MySQL must have compiled the SPs with the default only_full_group_by set originally. Therefore, even when I changed my.cnf and restarted mysqld it had no effect on the SPs, and they kept failing with "SELECT list is not in GROUP BY clause and contains nonaggregated column ... which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by".
Reloading the SPs must have caused them to be recompiled now with only_full_group_by disabled. After that, they seem to work as expected.
Apologies for not using your exact SQL
I used this query to overcome the Mysql warning.
SELECT count(*) AS cnt, `regions_id`
FROM regionables
WHERE `regionable_id` = '115' OR `regionable_id` = '714'
GROUP BY `regions_id`
HAVING cnt > 1
note the key for me being
count(*) AS cnt
If you don't want to make any changes in your current query then follow the below steps -
sudo vim /etc/mysql/my.cnf
A
to enter insert modeCopy and paste
[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Type esc
to exit input mode
:wq
to save and close vim.sudo service mysql restart
to restart MySQL.Addition of lines (mention below) in file : /etc/mysql/my.cnf
[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Work fine for me. Server version: 5.7.18-0ubuntu0.16.04.1 - (Ubuntu)
If you have this error with Symfony using doctrine query builder, and if this error is caused by an orderBy :
Pay attention to select
the column you want to groupBy
, and use addGroupBy
instead of groupBy
:
$query = $this->createQueryBuilder('smth')->addGroupBy('smth.mycolumn');
Works on Symfony3 -