end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

mysqlでは、group by で未指定のcolumnもselect可能

ただし、そのようなcolumnから、返されるrecordはmysqlが勝手に決めるみたい。
驚いた。でも、mysqlでは有名な話?

MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate. Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values within each group the server chooses.
http://dev.mysql.com/doc/refman/5.5/en/group-by-extensions.html