MySQL GROUP BY behavior

后端 未结 6 579
春和景丽
春和景丽 2020-11-29 06:53

Given the following table \'foo\'

ID | First Name | Last Name
----------------------------
67   John        Smith
----------------------------
6         


        
6条回答
  •  北海茫月
    2020-11-29 07:42

    MySQLs group by is not consistent with the standard SQL behaviour , MySQL makes it easy to get other columns BUT at the same time u can never be sure which one u will get.

    Update: refer to this page: http://dev.mysql.com/doc/refman/5.0/en/group-by-handling.html

    When using this feature, all rows in each group should have the same values for the columns that are ommitted from the GROUP BY part. The server is free to return any value from the group, so the results are indeterminate unless all values are the same.

提交回复
热议问题