43

Receiving the following error:

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'world.country.Code' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

When running the following query:

select countrylanguage.language, country.code, sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language
order by sum(country.population*countrylanguage.percentage) desc ;

Using the MySQL world test database (http://dev.mysql.com/doc/index-other.html). No idea why this is happening. Currently running MYSQL 5.7.10.

Any ideas??? :O

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Danny J. Williams
  • 431
  • 1
  • 4
  • 3

2 Answers2

31

As @Brian Riley already said you should either remove 1 column in your select

select countrylanguage.language ,sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language
order by sum(country.population*countrylanguage.percentage) desc ;

or add it to your grouping

select countrylanguage.language, country.code, sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language, country.code
order by sum(country.population*countrylanguage.percentage) desc ;
davejal
  • 6,009
  • 10
  • 39
  • 82
-3

country.code is not in your group by statement, and is not an aggregate (wrapped in an aggregate function).

https://www.w3schools.com/sql/sql_ref_sqlserver.asp

Derrick Moeller
  • 4,808
  • 2
  • 22
  • 48
Brian Riley
  • 926
  • 1
  • 7
  • 12