MySQL GROUP BY behavior

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

Given the following table \'foo\'

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


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 07:21

    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.

    True. Actually it corresponds more to SELECT DISTINCT ON mode in postgres for instance, except this allows you to specify the order of the rows prior to distinctization (?) and therefore which row you will get (ie most recent, oldest, whatever).

    Note MySQL in "sql compliant" mode will reject GROUP BY with nonspecified columns as in your example.

提交回复
热议问题