Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MySQL:O que acontece com campos não agregados em um GROUP BY?


MySQL> 5.7.5

É uma consulta ilegal.

Você receberá um erro como:
ERROR 1055 (42000): Expression #1 of SELECT list is not in 
GROUP BY clause and contains nonaggregated column 'a' 
which is not functionally dependent on columns in 
GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Mais detalhes em https://dev.mysql. com/doc/refman/5.7/en/group-by-handling.html

MySQL <5.7.5

Resposta curta:é uma consulta válida, mas o servidor está livre para retornar qualquer valor

Lendo este https://dev.mysql.com /doc/refman/5.0/en/group-by-handling.html mostra:

Portanto, não há como determinar qual será esse valor (se houver mais valores para esse grupo)