SQL vs MySQL: Rules about aggregate operations and GROUP BY

前端 未结 4 1701
遥遥无期
遥遥无期 2021-02-14 05:11

In this book I\'m currently reading while following a course on databases, the following example of an illegal query using an aggregate operator is given:

4条回答
  •  后悔当初
    2021-02-14 05:52

    By the way, it is default MySQL behavior. But it can be changed by setting ONLY_FULL_GROUP_BY server mode in the my.ini file or in the session -

    SET sql_mode = 'ONLY_FULL_GROUP_BY';
    SELECT * FROM sakila.film_actor GROUP BY actor_id;
    
    Error: 'sakila.film_actor.film_id' isn't in GROUP BY
    

    ONLY_FULL_GROUP_BY - Do not permit queries for which the select list refers to nonaggregated columns that are not named in the GROUP BY clause.

提交回复
热议问题