Error related to only_full_group_by when executing a query in MySql

前端 未结 18 2557
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:39

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

18条回答
  •  无人及你
    2020-11-21 05:08

    you can turn off the warning message as explained in the other answers or you can understand what's happening and fix it.

    As of MySQL 5.7.5, the default SQL mode includes ONLY_FULL_GROUP_BY which means when you are grouping rows and then selecting something out of that groups, you need to explicitly say which row should that selection be made from.

    Mysql needs to know which row in the group you're looking for, which gives you two options

    • You can also add the column you want to the group statement group by rect.color, rect.value which can be what you want in some cases otherwise would return duplicate results with the same color which you may not want
    • you could also use aggregate functions of mysql to indicate which row you are looking for inside the groups like AVG() MIN() MAX() complete list
    • AND finally you can use ANY_VALUE() if you are sure that all the results inside the group are the same. doc

提交回复
热议问题