SQL vs MySQL: Rules about aggregate operations and GROUP BY

前端 未结 4 1710
遥遥无期
遥遥无期 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:44

    Is the query above really illegal in SQL, but legal in MySQL

    Yes

    if so, why is that

    I don't know the reasons for the design decisions made in MySQL, but considering that you can get the actual related data from the same row(s) as the aggregate came from (e.g., MAX or MIN) with only slightly more work, I don't see any advantage in returning additional column data from arbitrary rows.

    I strongly dislike this "feature" in MySQL and it trips up many people who learn aggregates on MySQL and then move to a different dbms, and suddenly realize they never quite knew what they were doing.

提交回复
热议问题