Select list contains nonaggregated column

喜你入骨 提交于 2019-12-04 14:43:53

You can do one of two things:

1) change your query so that everything in the select clause is aggregated. Something like this

SELECT u.email, p.name as plan, COUNT(u.id) as totalprojects FROM users u LEFT JOIN plans p ON p.id = access LEFT JOIN maps m ON m.user_id = u.id WHERE u.email = 'john@doe.com' group by u.email;

2) Change the sql mode to allow mysql to run your query. Something like this

[mysqld]
sql_mode = "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

in your my.cnf file.

Note that this sets various sql_mode options. You can read about them here: http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

On my Node server with Digital Ocean the conference file I needed to edit was located /etc/mysql/mysql.conf.d/mysqld.cnf

Adding in the following

[mysqld] sql_mode = "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

And then service mysql restart fixes the issue.

the easiest solution is ANY_VALUE function: ANY_VALUE official documentation

SELECT name, ANY_VALUE(address), MAX(age) FROM t GROUP BY name;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!